python模块之keyword

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python模块之keyword



import keyword
'''
>>> help(keyword)
Help on module keyword:

FUNCTIONS
    iskeyword = __contains__(...)
        x.__contains__(y) <==> y in x.

DATA
    __all__ = ['iskeyword', 'kwlist']
    kwlist = ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', ...

'''

#判断一个字符串是不是关键词
print keyword.iskeyword('for')#True


#导出所有关键词
print 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']
'''

 

posted @ 2015-11-21 16:39  Xiao|Deng  阅读(789)  评论(0编辑  收藏  举报