Python – Variable Names

1. What is a Variable Name?

A variable name is the name of the box where we store data.

Example:

age = 25

Here:

  • age is the variable name

  • 25 is the value

2. Why Variable Names Are Important

Good variable names make your code:
✔ Easy to read
✔ Easy to understand
✔ Easy to fix later

Bad names make code confusing 😕

3. Rules for Variable Names in Python

Python has some simple rules.
You must follow these rules, or Python will give an error.

✅ Rule 1: Start with a Letter or _

✔ Allowed:

name = "Amit"
_age = 20

❌ Not Allowed:

1name = "Error"

✅ Rule 2: Use Only Letters, Numbers, and _

✔ Allowed:

student_name = "Ravi"
marks1 = 80

❌ Not Allowed:

total-marks = 90
my name = "Rahul"

✅ Rule 3: No Python Keywords

You cannot use Python reserved words.

❌ Wrong:

class = 10
if = 5

✔ Correct:

class_name = "Ten"
if_value = 5

✅ Rule 4: Variable Names Are Case-Sensitive

name = "Amit"
Name = "Ravi"

These are two different variables.

4. Good Variable Naming Style (Best Practice)

Python uses snake_case.

Good Names 👍

student_name = "Anita"
total_marks = 450
user_age = 21

Bad Names 👎

x = 10
tm = 450
a1 = 21

(These work, but are hard to understand.)

5. Short vs Meaningful Names

Bad Example

x = 500

Good Example

total_price = 500

Meaningful names are better.

6. Multiple Variable Names

Example

first_name = "Rahul"
last_name = "Sharma"

7. Common Beginner Mistakes

❌ Using Spaces

my name = "Ravi"

✔ Correct:

my_name = "Ravi"

❌ Starting with Number

2age = 20

✔ Correct:

age2 = 20

8. Practice Examples

Example 1: Correct Names

book_title = "Python Basics"
page_count = 120
price = 299

Example 2: Fix the Wrong Names

❌ Wrong:

1price = 100
total-price = 500

✔ Correct:

price1 = 100
total_price = 500

9. Summary (Variable Names)

✔ Variable name is the name of the data box
✔ Must start with letter or _
✔ No spaces or special symbols
✔ No Python keywords
✔ Use meaningful names

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School students

  • Self-learners

If you want next, I can write:

  • Python Data Types

  • Python Operators

  • if–else statements

  • Loops (for, while)

  • Practice questions with answers

Just tell me 😊

You may also like...