keyword.iskeyword()
keyword.iskeyword() is a Python function in the Keyword Module category. Returns True if s is a Python keyword. The syntax is keyword.iskeyword(s). Parameters: s — string to test. Returns: Boolean. A typical example: import keyword
keyword.iskeyword("for") # True
keyword.iskeyword("hello") # False. A close sibling is keyword.kwlist, which a list of all Python keywords in the current version. A close sibling is keyword.softkwlist, which a list of Python soft keywords (that can be used as identifiers). More about this category: Python keyword testing — iskeyword, kwlist, softkwlist. Related Keyword Module entries: keyword.kwlist, keyword.softkwlist. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try keyword.iskeyword() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.