知行编程网知行编程网  2022-09-15 10:30 知行编程网 隐藏边栏  8 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于Python中关键字有多少个?的相关知识,包括python中定义的关键字是什么,以及python中使用函数的优点这些编程知识,希望对大家有参考作用。

Python中有多少关键字? Python 中目前有 31 个关键字,你可以使用 Python 内置的关键字模块来查看输出。

Python中有多少关键字?


keyword模块

Help on module keyword:
NAME
  keyword - Keywords (from "graminit.c")
FILE
  /usr/lib64/python2.6/keyword.py
DESCRIPTION
  This file is automatically generated; please don't muck it up!
  To update the symbols in this file, 'cd' to the top directory of
  the python source tree after building the interpreter and run:
    python Lib/keyword.py
FUNCTIONS
  iskeyword = __contains__(...)
    x.__contains__(y)  y in x.
DATA
  __all__ = ['iskeyword', 'kwlist']
  kwlist = ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', ...


得到python的关键字列表:

>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',
 'raise', 'return', 'try', 'while', 'with', 'yield']

更多相关内容:


判断字符串是否是python的关键字

>>> keyword.iskeyword('and')
True
>>> 
>>> keyword.iskeyword('has')
False

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享