< BACKMake Note | BookmarkCONTINUE >
152015024128143245168232148039199167010047123209178152124239215162146127173243174102010110

keyword

The keyword module tests whether a string is a Python keyword. Note that the keyword-checking mechanism is not tied to the specific version of Python being used.

keyword.kwlist

This is a list of all Python keywords.

						
>>> import keyword
>>> keyword.kwlist
['and', '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']

					

keyword.iskeyword()

This function tests whether a string is a Python keyword:

						
>>> import keyword
>>> str = "import"
>>> keyword.iskeyword(str)
1

					


Last updated on 1/30/2002
Python Developer's Handbook, © 2002 Sams Publishing

< BACKMake Note | BookmarkCONTINUE >

© 2002, O'Reilly & Associates, Inc.