Chinaunix

标题: keyword-Testing for Python keywords [打印本页]

作者: pywugw    时间: 2009-12-31 00:29
标题: keyword-Testing for Python keywords

                                keyword用来判断指定的字符串是否为关键字
keyword.iskeyword(s)Return true if s is a Python keyword.
keyword.kwlistSequence containing all the keywords defined for the interpreter.  If any
keywords are defined to only be active when particular __future__ statements are in effect, these will be included as well.
Example:
               
               
               
               
               
               
                Python 2.6.4 (r264:75706, Dec 31 2009, 07:25:24)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyword
>>> keyword.iskeyword('and')
True
>>> keyword.iskeyword('list')
False
>>> keyword.iskeyword('or')
True
>>> 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']


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/109054/showart_2135983.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2