Learn Python
>>> getting_started.keywords_identifiers

Keywords and Identifiers in Python

#concept

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.

#how it works
1

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.

2

Start with a letter or underscore

A valid identifier must begin with a letter (a-z, A-Z) or an underscore — never a digit.

3

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.

4

Case matters

age, Age, and AGE are three completely different identifiers to Python — capitalization is never ignored.

5

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.

#example
# valid identifiers
user_name = "Maya"
_temp = 42
score2 = 100
 
# for = "oops" # would raise a SyntaxError — 'for' is a keyword, not a valid identifier
 
print(user_name, _temp, score2)
Output
Maya 42 100
1user_name, _temp, and score2 are all valid identifiers — each starts with a letter or underscore and contains only letters, digits, and underscores after that.
2The commented-out line shows what not to do: for is one of Python's reserved keywords, so using it as a variable name is a syntax error, not just bad style — which is why it's commented out rather than actually run.
3print() accepts multiple values separated by commas and prints them space-separated by default.
#use cases
Avoiding a whole category of beginner errors — SyntaxError: invalid syntax caused by accidentally naming something for, class, or True
Writing self-documenting code, since user_name tells the next reader far more than x does
Following PEP 8 naming conventions so code looks familiar to any other Python developer who reads it
Correctly interpreting error messages that mention "keyword" or "identifier" instead of guessing what they mean

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.