🧪 Python Variables – Practice Exercises with Solutions | TechTown.in
Learning Python is not just about reading — it’s about practicing. And when it comes to variables, there’s no better way to understand how they work than by solving real code challenges.
In this guide, we bring you Python variable exercises for beginners, complete with solutions and explanations. Test yourself, spot your mistakes, and master variable assignment, output, and scope with confidence!
✅ Exercise 1: Create a Variable and Print It
🔹 Question:
Create a variable named carname and assign the value "Volvo" to it. Then print it.
✅ Solution:
carname = "Volvo"
print(carname)
✅ Exercise 2: Assign Multiple Variables
🔹 Question:
Create variables x, y, and z, and assign them the values "Orange", "Banana", and "Cherry" respectively in one line.
✅ Solution:
x, y, z = "Orange", "Banana", "Cherry"
✅ Exercise 3: One Value to Multiple Variables
🔹 Question:
Create three variables x, y, and z, and assign them the same value "Python".
✅ Solution:
x = y = z = "Python"
✅ Exercise 4: Output Variables
🔹 Question:
Print the word “awesome” stored in a variable called txt.
✅ Solution:
txt = "awesome"
print(txt)
✅ Exercise 5: Combine Text and Variables
🔹 Question:
Use the print() function to output the following using two variables:
x = "Python"
y = "is awesome"
Expected Output:
Python is awesome
✅ Solution:
x = "Python"
y = "is awesome"
print(x, y)
✅ Exercise 6: Add Two Numbers
🔹 Question:
Create two variables x and y and assign them the values 5 and 10. Print the sum of x and y.
✅ Solution:
x = 5
y = 10
print(x + y)
✅ Exercise 7: Output With Text
🔹 Question:
Add a variable z = x + y, then print “The sum is” followed by the result.
✅ Solution:
x = 5
y = 10
z = x + y
print("The sum is", z)
✅ Exercise 8: Variable Type Casting
🔹 Question:
Convert the integer 5 into a string and assign it to the variable x.
✅ Solution:
x = str(5)
✅ Exercise 9: Variable Name Case Sensitivity
🔹 Question:
Fix the error in the code below:
a = 4
A = "Sally"
print(a, A)
✅ Solution:
✅ This is already valid! It demonstrates that Python is case-sensitive, so a and A are two different variables.
🧠 Quick Practice Tips
- Always try solving the problem before checking the solution
- Use meaningful variable names in real-world projects
- Mix different data types (strings, integers) for realistic practice
- Experiment with f-strings,
str(), andinput()for added challenge
🏁 Final Words
Practicing these Python variable exercises helps build a solid foundation. Variables are the building blocks of every Python script you’ll ever write — get comfortable with them now, and everything else becomes easier.
🚀 Keep Practicing on TechTown.in

