String Methods

str.isidentifier()

Check the lexical shape of a Python identifier, including permitted Unicode characters. Reserved keywords can still pass; use keyword.iskeyword() separately, and consider contextual soft keywords. A leading decimal digit is invalid, while an underscore is permitted. Identifier normalization can merge distinct source spellings, so this is not a uniqueness or security check. Takes no arguments.

Formal Syntax & Structure

python syntaxpython
text.isidentifier()

Return Value

bool

True when the stated classification holds; otherwise False.

Working Example

Example Snippetpython
import keywordfor name in ("user_2", "نام", "2user", "class", "match"):    print(name, name.isidentifier(), keyword.iskeyword(name))
Python Reference