"exit" is not a keyword in Python, but no error occurs when using it

I find out what is exitnot a keyword in Python,

import keyword
print('exit' in keyword.kwlist)     # Output: False

But when using this word no NameError: name 'exit' is not defined. The output of the following code allows me to be confused. Can anyone help me out?

for i in range(5):
    print(i)
    cur=i if i<2 else exit

print(cur)
# Output
0
1
2
3
4
Use exit() or Ctrl-D (i.e. EOF) to exit

I cannot get related information exitfrom the Python documentation except exit([code=None]).

+2
source share
3 answers

python. (, for, del, if...). . , .

(, , , ), python . , sorted, id, vars,...

, exit - , . sys.exit.

+4

exit - Quitter. Quitter __repr__, , exit . __call__. , __init__ , , __call__, . exit() __call__, .

+2

exit - sys.exit, .

, (, sum, int...). , ,

0

All Articles