This is different, there is no special case handling here for you typing "exit".
Python functions are invoked with parenthesis, while typing a name without parenthesis retrieves the content of a variable. The Python CLI helpfully sets the "exit" variable to that string so that you don't get a confusing NameError when you make this mistake.
If the `exit` variable were set to a string, `exit()` would be an error because you can't use `()` on strings. `exit` is a callable whose `__str__` method returns that message.
Note that this isn't specific to the REPL. Running `print(exit)` in a Python script will print the same message.
I'd say that would be much more surprising and unintuitive behavior just for the sake of slightly more convenient REPL use. I wouldn't want stringifying any function to automatically call it. What if you store the function somewhere and print it for debugging, and then have to figure out why your program keeps crashing when you try to just print a list of functions?
Besides, you usually have a more convenient exit available with Ctrl-D anyway.
Yeah but I can also say it’s a surprise to see instructions on how to exit the REPL when printing a list of functions. Honestly I think there should be no special case, and the REPL should print the “how to exit” text upon startup. As is, the user still has to guess ‘exit’ rather than ‘quit’ ‘abort’ ‘stop’ ‘bye’ etcetera to get the help text. (edit: actually they have the text on 'quit' as well)
Python functions are invoked with parenthesis, while typing a name without parenthesis retrieves the content of a variable. The Python CLI helpfully sets the "exit" variable to that string so that you don't get a confusing NameError when you make this mistake.