如何查看Python中所有关键字

一、保留字即关键字,我们不能把它们用作任何标识符名称。Python的标准库提供了一个keyword模块,可以输出当前版本的所有关键字

import keyword
print(keyword.kwlist)
print(keyword.iskeyword ('False'))#判断是否是关键字
print(keyword.iskeyword ('China'))#判断是否是关键字

二、对应所有关键字如下面列表所示

keyword=['False', 'None', 'True', '__peg_parser__', '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']

 

 

posted @ 2021-12-01 21:16  悬崖上的金鱼  阅读(1045)  评论(0)    收藏  举报