Write any Python at all and you spend a surprising amount of time naming things: variables, functions, classes. The names you make up are called identifiers, and there are a few simple rules for what you're allowed to use. Sitting next to them is a small set of words Python has already taken for itself, called keywords, and those are off limits as names. Once you know the difference and the handful of rules, a whole batch of beginner errors just stops happening.
So we'll cover both. You'll see how to list every keyword, sort them into groups so the list feels less scary, and pick up the naming style experienced programmers actually use.
Keywords vs identifiers
Keywords are reserved words that already mean something specific in Python, like if, for, and def. Identifiers are the names you choose yourself for your variables, functions, and classes. The one rule that ties them together: you can't use a keyword as one of your own names.

What are keywords?
Keywords are the building blocks of the language's grammar. Python reserves them so they always do their one job, which means they can never double as a variable name. There are around 35, and you don't have to sit down and memorize the list. You'll pick them up as you write code.
You can see the whole list any time with Python's built in keyword module:
import keyword
print(keyword.kwlist)
# Output: ['False', 'None', 'True', 'and', 'as', 'assert', ... ]
Try to use one as a name and you get an error, because Python is expecting that word to do its special job:
for = 5
# SyntaxError: invalid syntax
Keywords grouped by job
The list goes down easier once you notice the keywords fall into a few groups based on what they do. You don't need to learn them all today, but the groups give you a map to come back to.

- Values,
True,False,None. - Logic,
and,or,not,in,is. - Control flow,
if,elif,else,for,while,break,continue. - Functions and classes,
def,return,lambda,class. - Other handling,
try,except,finally,with,import.
Soft keywords
There's also a small group called soft keywords. These behave specially only in certain spots, and elsewhere you can still use them as ordinary names. The main ones are match, case, type, and the underscore _. As a beginner you'll rarely bump into them, but it's good to know they exist so the names don't surprise you later.

What are identifiers?
An identifier is just a name you give to something. Every variable, function, and class you create has one. Good identifiers are descriptive, so the code reads clearly without you needing a comment on every line.
user_name = "Riya"
total_score = 95
def calculate_average(numbers):
return sum(numbers) / len(numbers)
print(user_name, total_score)
# Output: Riya 95
Rules for a valid identifier
There are a few firm rules for what an identifier can look like. Break one and Python won't run the line.

Here they are:
- It can contain letters, digits, and underscores (
a to z,A to Z,0 to 9,_). - It must not start with a digit.
name1is fine,1nameis not. - It can't contain spaces or symbols like
-,@, or!. Use an underscore in place of a space. - It can't be a keyword.
- It's case sensitive, so
totalandTotalare different names.
age = 25 # valid
_count = 0 # valid, underscores are allowed
user2 = "ok" # valid, a digit is fine after a letter
print(age, _count, user2)
# Output: 25 0 ok
Name things clearly
Following the rules makes a name legal. A good name does more than that: it tells the reader what the thing holds. Descriptive names make code much easier to follow, while single letters and vague words leave people guessing.

# Clear: you can read the intent
total_price = 250
is_logged_in = True
# Vague: what do these hold?
x = 250
flag = True
print(total_price, is_logged_in)
# Output: 250 True
Naming conventions
On top of the rules, Python programmers share a few conventions for how names should look. Python doesn't enforce these, but pretty much everyone follows them, so your code fits in and reads the way other people expect.

- snake_case for variables and functions, like
user_nameandcalculate_total. - PascalCase for classes, like
StudentandBankAccount. - UPPER_CASE for constants, values you don't plan to change, like
MAX_SIZEandPI.
MAX_USERS = 100 # constant
default_name = "guest" # variable
def get_user_count(): # function
return 42
print(MAX_USERS, default_name, get_user_count())
# Output: 100 guest 42
Check if a word is a keyword
If you're not sure whether a word is reserved, ask Python straight out with keyword.iskeyword(). It hands back True or False.
import keyword
print(keyword.iskeyword("class")) # Output: True
print(keyword.iskeyword("student")) # Output: False
Practice exercises
Type each one out and run it.
Count the keywords
Print how many keywords Python has using the keyword module.
# Solution
import keyword
print(len(keyword.kwlist))
# Output: 35 (the number for your Python version)
A clear name
Create a well named variable for a person's email and print it.
# Solution
user_email = "[email protected]"
print(user_email)
# Output: [email protected]
Check two words
Use keyword.iskeyword() to check whether "return" and "result" are keywords.
# Solution
import keyword
print(keyword.iskeyword("return")) # Output: True
print(keyword.iskeyword("result")) # Output: False
Fix the name
The name 2nd_score is invalid. Rewrite it as a valid identifier and assign it a value.
# Solution
second_score = 88
print(second_score)
# Output: 88
Common mistakes
- Using a keyword as a name.
class = 5orfor = 1fails. Pick a different word likeclass_name. - Starting a name with a digit.
2nd_placeis invalid; useplace_2orsecond_place. - Using a hyphen or space.
user-nameanduser nameboth break. Useuser_name. - Ignoring case. Defining
Totalthen usingtotalrefers to two different names and causes aNameError. - Vague names.
xanddata2are legal but unclear. Descriptive names make code easier to read. - Shadowing built ins. Naming a variable
listorsumworks but hides the built in function of the same name, which causes confusing bugs later.
Frequently asked questions
How many keywords does Python have?
Around 35 in current versions. The exact number shifts a little between versions, so check with len(keyword.kwlist) on your own Python.
What is the difference between a keyword and an identifier?
A keyword is a reserved word with a fixed meaning, like if or def. An identifier is a name you choose for your variables, functions, and classes. You can't use a keyword as an identifier.
Can an identifier start with an underscore?
Yes. Names like _count are fine. A leading underscore often signals a name is meant for internal use, but Python allows it normally.
Are Python identifiers case sensitive?
Yes. score, Score, and SCORE are three different identifiers, so stay consistent with your capitals.
Can I use numbers in a variable name?
Yes, as long as the name doesn't start with one. player1 is valid; 1player is not.
What are soft keywords?
Words like match, case, and type that are special only inside certain statements. Anywhere else you can still use them as ordinary names, unlike the regular reserved keywords.
Key takeaways
- Keywords are reserved words with a fixed meaning; you can't use them as names.
- They fall into groups: values, logic, control flow, functions and classes, and handling.
- Identifiers are the names you choose; they use letters, digits, and underscores, never start with a digit, and can't contain spaces or hyphens.
- Follow conventions: snake_case for variables and functions, PascalCase for classes, UPPER_CASE for constants.
- Use the
keywordmodule to list keywords or check a word, and avoid shadowing built in names.
Now that you can name things properly and know which words to steer clear of, the natural next move is to start using those names. The lesson on Python variables picks it up from here, showing how values get stored and reused.

By Kaustubh Saini 