1. 关键字
and
as
assert
break
class
continue
def
del
elif
else
except
exec
finally
for
from
global
if
import
in
is
lambda
nonlocal
not
or
pass
raise
return
try
while
with
yield
1) Python 2.4中None变成了常数,Python 3.0中None、True、False变成了关键字
2)print、exec变成了内置函数,Python 3.0 中作为关键字移除。
3)为了简化并更好地标识异步IO,从Python 3.5开始引入了新的关键字async和await,
False
None
True
and
as
assert
break
class
continue
def
del
elif
else
except
finally
for
from
global
if
import
in
is
lambda
nonlocal
not
or
pass
raise
return
try
while
with
yield
代码实现输出Python关键字的个数和列表
本人使用的Python版本是 Python 3.8.0,如何查看Python的版本如下:window+R-->cmd-->python -E0
import keyword
print(len(keyword.kwlist)) #33
print(keyword.kwlist) #打印关键字
输出结果:
35
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']