A variable is created the moment you assign a value to it. You do not declare a type.
Names can contain letters, numbers and underscores, and cannot start with a number.
Names are case-sensitive: age and Age are different.
The convention is snake_case: first_name, total_price.
Assign several at once: x, y, z = 1, 2, 3
Variables declared outside functions are global.
💡 Key Takeaways: Python Variables
Mastering Python Variables helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Python Variables Code Example
Python
name = "Usman"
age = 27
first_name = "Ali"
x, y, z = "Lahore", "Karachi", "Quetta"
a = b = c = 0
print(name, age)
print(x, y, z)
print(a, b, c)
age = "twenty-seven" # a variable can change type
print(age)
Free sign-in required · Google login available
Python Variables Practice Exercises
Check what you learned in “Python Variables”.
/ 3 solved
Fill in the blank
Assign three variables in one line.
x, y, z =
✓ Correct!Not quite. Try again.
Multiple choice
Which is a valid variable name?
✓ Correct!Not quite. Try again.
Code challenge
Create a variable city = "Quetta" and print it.
Write the code in the live editor. Your answer is checked automatically.