Naming Rules for
PYTHON
Variables
Python Variable Names –
Rules you need to know!
Naming variables correctly makes
your code clearer and easier to read.
Let’s go over some rules! 🚀
Rule 1
Start with a Letter or Underscore
A variable name must start with a letter (A-Z,
a-z) or an underscore (_), but never a
number.
✅ Correct: name, _age
❌ Incorrect: 2name
Rule 2
Only Use Letters, Numbers, and
Underscores
Variable names cannot contain spaces or
special characters!
✅ Correct: my_variable, score1
❌ Incorrect: my-variable, first name
Rule 3
Python is Case-Sensitive
Python treats uppercase and lowercase letters
as different variables!
✅ These are all separate variables:
· age
· Age
· AGE
Rule 4
Avoid Python Keywords
You cannot use Python’s built-in keywords as
variable names.
❌ Incorrect: class, def
✅ Correct: class_name, function_def
Rule 5
Use Readable Multiword Names
There are different ways to format multiword
variable names:
🐍 Snake Case (Recommended in Python):
my_variable_name
🐫 Camel Case: myVariableName
🔠 Pascal Case: MyVariableName
Recap
✔️ Start with a letter or underscore
✔️ Use only letters, numbers, and underscores
✔️ Remember that Python is case-sensitive
✔️ Avoid using Python keywords
✔️ Use snake_case for better readability
Want to Learn More?
This was just a quick overview of Python
variable names.
Explore more about naming rules, case
sensitivity, legal characters, and best
practices for variable names in detail at
www.w3schools.com