Python lesson
Variables
= means 'store this value under this name'. Storing a new value replaces the old one, so the second print shows 40.
Try this lesson free →Example
A variable is a name that holds a value. You set it with =, then use the name instead of the value:
price = 35
print(price)
price = 40
print(price)35
40Key points
price = 35Store 35 in a variable called price. The name goes on the left.
print(price)No quotes, so Python looks up the value stored in price.
print("price")With quotes it's just text, so this shows the word price.
Names can use letters, numbers and underscores, like unit_price. No spaces.
Practice
1. Build a line that stores 35 in a variable called price.
price = 352. Build a line that shows the value stored in total.
print(total)3. Create a variable called qty that holds 3, then print it.
qty = 3
print(qty)4. Store the text Charger in a variable called product, then print product.
product = "Charger"
print(product)5. Set city to Lagos. On the next line, change it to Abuja. Then print city.
city = "Lagos"
city = "Abuja"
print(city)Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →