ID EN
Built-in Types

isidentifier

Python 3.11

Return True if the string is a valid identifier according to the language definition, section Identifiers and keywords.

Syntax

PYTHON
str.isidentifier()

Examples

Example 1
PYTHON
>>> from keyword import iskeyword

>>> 'hello'.isidentifier(), iskeyword('hello')
(True, False)
>>> 'def'.isidentifier(), iskeyword('def')
(True, True)

See Also

Identifiers and keywords keyword.iskeyword() def class