Python中所有的关键字

在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
原文地址:https://www.cnblogs.com/xiaohanzi/p/10038455.html