Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Anvi Jain

The keyword module in Python's standard library allows a Python program to determine if a string is a keyword.

keyword.iskeyword(s): This function returns true if s is a Python keyword.

keyword.kwlist: This attribute returns Sequence containing all the keywords defined for the interpreter. If any keywords are to be appearing in future versions, these will be included as well.

>>> import keyword
>>> kwlist = keyword.kwlist
>>> kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']
>>> kw = input('enter a keyword..')
enter a keyword..catch
>>> kw in kwlist
False
>>> kw = input('enter a keyword..')
enter a keyword..import
>>> kw in kwlist
True

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.