Python基础 快速查看Python中有多少个关键字

简介: 珍惜当下,把自己的善意和情感留给真正值得的人!

Python中关键词有多少个?Python中关键词目前有31个,可以利用Python的内置的keyword模块进行输出查看。

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
相关文章
|
6月前
|
程序员 开发者 Python
05 python - 标示符和关键字
05 python - 标示符和关键字
25 0
|
4天前
|
数据采集 关系型数据库 MySQL
python-协程(async、await关键字与asyncio)
python-协程(async、await关键字与asyncio)
98 0
|
4天前
|
Python
【python】—— 内置类型、运算符、表达式、关键字
【python】—— 内置类型、运算符、表达式、关键字
135 1
|
4天前
|
存储 大数据 PHP
python里yeild关键字有什么用?
python里yeild关键字有什么用?
8 0
|
4天前
|
Python
Python yield 关键字的作用?
Python yield 关键字的作用?
8 0
|
4天前
|
Python
Day4作用域,Python关键字global和nonlocal使用
作用域,Python关键字global和nonlocal使用
4 0
|
4天前
|
Python
Python 的异步编程:什么是异步编程?Python 中的 `async` 和 `await` 关键字是用来做什么的?
Python 的异步编程:什么是异步编程?Python 中的 `async` 和 `await` 关键字是用来做什么的?
|
4天前
|
Python
Python 的异步编程:什么是异步编程?Python 中的 `async` 和 `await` 关键字是用来做什么的?
【4月更文挑战第14天】Python中的异步编程利用`async`和`await`关键字提升并发性能和响应速度。异步函数在等待操作时可暂停,协程是轻量级线程,实现任务间切换。示例展示了如何定义异步函数和协程,以及如何通过`asyncio`库并发执行任务。
14 1
|
4天前
|
Python
Python中的35个关键字
Python中的35个关键字
16 2
|
4天前
|
Java API PHP
多多关键字API php java Python
多多关键字API接口广泛应用于商家进行市场分析、竞品分析、关键词优化等场景。商家可以通过分析关键词数据,了解用户需求,制定针对性的营销策略,提高产品的曝光率和转化率。