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选择排序算法实例总结

本文实例总结了python选择排序算法。分享给大家供大家参考。具体如下: 代码1: def ssort(V): #V is the list to be sorted j = 0...

详解Python中用于计算指数的exp()方法

 exp()方法返回指数x: ex. 语法 以下是exp()方法的语法: import math math.exp( x ) 注意:此函数是无法直接访问的,所以我们...

Python发展简史 Python来历

Python发展简史 Python来历

Python是我喜欢的语言,简洁,优美,容易使用。前两天,我很激昂的向朋友宣传Python的好处。 听过之后,朋友问我:好吧,我承认Python不错,但它为什么叫Python呢? 我不是...

对Django 转发和重定向的实例详解

对Django 转发和重定向的实例详解

转发和重定向: 转发:一次请求和响应,请求的地址没有发生变化,如果此时刷新页面,就会出现重做现象。 重定向:一次以上的请求和响应,请求地址发生一次以上的变化,如果此时刷新页面,就不会发生...

Sanic框架Cookies操作示例

本文实例讲述了Sanic框架Cookies操作。分享给大家供大家参考,具体如下: 简介 Sanic是一个类似Flask的Python 3.5+ Web服务器,它的写入速度非常快。除了Fl...