Python Variables

1. What is a Variable?

A variable is like a box.
It is used to store information.

Example:

age = 25

Here:

  • age → variable name

  • 25 → value stored in the box

2. Creating a Variable in Python

In Python, creating a variable is very easy.
You just write the name and give a value.

Example

name = "Ravi"
city = "Delhi"

Python automatically understands the type.

3. Python is Smart (No Data Type Needed)

You do NOT need to write:

  • int

  • float

  • string

Python decides it by itself.

Example

x = 10 # number
x = "Hello" # text
x = 5.5 # decimal

The same variable can change value.

4. Variable Naming Rules (Very Important)

✔ Must start with a letter or _
✔ Can contain letters, numbers, _
❌ Cannot start with a number
❌ Cannot use Python keywords

Correct Variable Names

student_name = "Amit"
age1 = 20
_total = 500

Wrong Variable Names

1name = "Error"
class = 10
total-marks = 80

5. Assigning Multiple Values

Many Variables, Many Values

a, b, c = 10, 20, 30
print(a, b, c)

One Value, Many Variables

x = y = z = 100

6. Printing Variables

Example

name = "Suman"
age = 22
print(name)
print(age)

Print Text with Variable

print("Name:", name)
print("Age:", age)

7. Variables with User Input

Example

name = input("Enter your name: ")
print("Hello", name)

Number Input

age = int(input("Enter your age: "))
print("Next year age:", age + 1)

8. Updating Variable Value

You can change a variable anytime.

Example

count = 5
count = count + 1
print(count)

Output:

6

9. Deleting a Variable

Example

x = 10
del x

After deleting, x cannot be used.

10. Common Beginner Mistakes

❌ Using Quotes with Variable

name = "Amit"
print("name")

Output:

name

✔ Correct:

print(name)

❌ Forgetting Type Conversion

age = input("Enter age: ")
print(age + 1)

✔ Correct:

age = int(input("Enter age: "))
print(age + 1)

11. Simple Practice Examples

Example 1: Store and Print

color = "Blue"
print(color)

Example 2: Add Two Numbers

a = 10
b = 20
sum = a + b
print("Sum:", sum)

Example 3: Update Variable

score = 50
score = score + 10
print(score)

12. Summary (Python Variables)

✔ Variables store data
✔ Python decides data type
✔ Variable names have rules
✔ Values can be changed
✔ Input can be stored in variables

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Python Data Types (easy)

  • Python Input & Output

  • Operators

  • if–else statements

  • Practice questions with answers

Just tell me 😊

You may also like...