Python中的关键字
解释器版本: Python3.6
查看python中的关键字
import keyword
print(keyword.kwlist)
['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']
看下一共多少个关键字 (3.6版本中)
print(len(keyword.kwlist))
一共33个
让我们来梳理一下这些关键字都是干嘛的
None
空
del
删除
with
上下文
assert
断言
lambda
匿名函数
True False
布尔
from import as
导包
def class
定义函数和类
if elif else
条件判断
for in while
循环语句
is or and not
逻辑判断
continue break
结束循环
global nonlocal
全局变量
pass return yield
函数返回
try except finally raise
异常处理