This article mainly introduces the usage of the python keyword module. The example analyzes the basic usage skills of the keyword module in Python. if you need it, refer to the example below to describe the usage of the python keyword module. Share it with you for your reference. The details are as follows:
Help on module keyword:NAME keyword - Keywords (from "graminit.c")FILE /usr/lib64/python2.6/keyword.pyDESCRIPTION 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.pyFUNCTIONS iskeyword = __contains__(...) x.__contains__(y) y in x.DATA __all__ = ['iskeyword', 'kwlist'] kwlist = ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', ...
Obtain the python keyword list:
>>> Keyword. kwlist ['and', 'as', 'assert ', 'break', 'class', 'contine', 'Def', 'Del ', 'elif ', 'else', 'got t', 'exec ', 'Finally', 'For ', 'from', 'global', 'if', 'import', 'in ', 'Is ', 'lambda', 'not ',' or ', 'pass', 'print', 'raise ', 'Return', 'try', 'While ', 'with', 'yield '] determines whether the string is a python keyword.
>>> keyword.iskeyword('and')True>>> >>> keyword.iskeyword('has')False
The above is the analysis of the usage instance of the python keyword module. For more information, see PHP Chinese network (www.php1.cn )!