在python中若想查询python中有哪些关键字。
可以先导入keyword模块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']
如果将关键字作为标识符,则会出现以下报错:and= [1,2,1,3]
print(and)
File "E:/Selenium_Study/111.py", line 34
and= [1,2,1,3]
^
SyntaxError: invalid syntax
本文地址:http://itbyc.com/Python/21442.html
转载请注明出处。