Keywords and Identifiers in Python
Keywords are words Python reserves for its own grammar — if, else, for, while, def, class, import, True, False, None, and around two dozen others. They already mean something specific to the interpreter, so you can never use one as the name of a variable, function, or anything else you create.
Identifiers are the opposite: the names you choose — for variables, functions, classes, and modules. Python has simple rules for what counts as a valid identifier, and a widely followed convention (not a hard rule) for how to style them.
Keywords are off-limits as names
Using a reserved word like for or class as a variable name raises a SyntaxError immediately — Python won't let the ambiguity happen.
Start with a letter or underscore
A valid identifier must begin with a letter (a-z, A-Z) or an underscore — never a digit.
Letters, digits, and underscores after that
Every character after the first can be a letter, a digit, or an underscore — no spaces, hyphens, or other punctuation.
Case matters
age, Age, and AGE are three completely different identifiers to Python — capitalization is never ignored.
Follow the naming convention
By convention (PEP 8), variables and functions use snake_case (user_name) while classes use PascalCase (UserProfile) — the interpreter doesn't enforce this, but nearly all Python code follows it.
# valid identifiersuser_name = "Maya"_temp = 42score2 = 100 # for = "oops" # would raise a SyntaxError — 'for' is a keyword, not a valid identifier print(user_name, _temp, score2)Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.