python的keyword模块用法实例分析

yipeiwu_com5年前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

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python处理PHP数组文本文件实例

需求: 对一个配置文件进行处理,拿出可用的字符来拼接,下面是原始文本,我们要得到这样的结果, 复制代码 代码如下: redis -h 127.0.0.1 -p 6379 | select...

pytorch中如何使用DataLoader对数据集进行批处理的方法

pytorch中如何使用DataLoader对数据集进行批处理的方法

最近搞了搞minist手写数据集的神经网络搭建,一个数据集里面很多个数据,不能一次喂入,所以需要分成一小块一小块喂入搭建好的网络。 pytorch中有很方便的dataloader函数来方...

python: 判断tuple、list、dict是否为空的方法

Test tuple_test = () assert not tuple_test list_test = [] assert not list_test dict_test...

浅析Python函数式编程

Functional Programming,函数式编程。Python对函数式编程提供部分支持。对于纯函数编程,对任一函数,只要输入是确定的,输出就是确定的,可称之为无副作用。 一、高阶...

python flask web服务实现更换默认端口和IP的方法

flask web后台启动后会发现默认是 localhost 127.0.0.1:5000 如果需要修改,方便调试发布 可以采用以下方式运行 from flask import Fl...