1 / 13
🐍

Variables in Python

Learn how to store and use data in your programs

💡

What are variables?

Variables hold information (things like numbers or words) so the computer can remember them, and use them later.

🎯

Why use variables?

  • So that we don't have to write the same information over and over.
  • So we can easily change the values without rewriting the whole program.
  • They also make your code more readable and organised
💻 Example
name = "Sam"

This is a variable declaration, declaring that the variable: name holds the information: Sam

print("Your name is ", name")

This variable can be used in a print function.

Here, it would give the output, "Your name is Sam".

If we changed the variable's data to be name = "John", we would get the output, "Your name is John".

Question 1

Which of these is a valid variable name?

Question 2

What is the value stored in this variable?

name = "Sam"
Question 3

Can variable values change during program execution?

Question 4

What happens when you run this code?

score = 100
score = 200
print(score)
Question 5

Complete this variable assignment:

_____ = "Python is awesome!"
Question 6

What is printed here?


name = "Sam"
age = 17
gender = "Male"

print(name)
Question 7

What is printed here?


price = 100
tax = 5

print(price + tax)
Question 8

What is printed here?


price = 60
tax = 3

total = price + tax

print(total)
Question 9

Declare the variable: flavour and assign it the value Chicken

Question 10

Declare the variable: country and assign it the value France

Question 11

What wrong with this code?

president = Donald Trump
🎉

Excellent Work!

You've mastered Python variables!

🏆

Variables Expert

You can now create and use variables in Python

What's Next?

Continue your Python journey with data types and operators!