Python Glossary Русский

Python 3.0+Strings (str)function

str.isidentifier

character checks

True if the string is a valid Python identifier (keywords included).

Syntax

s.isidentifier()

The method judges the shape of the name, not whether the name is usable: keywords like for and class pass, even though you can never assign to them. When validating a generated or user-supplied name, pair it with a second check, keyword.iskeyword().

Examples

print('x1'.isidentifier())    # → True
print('1x'.isidentifier())    # → False
print('for'.isidentifier())   # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy