TalentJR

🐍 Python for kids · Class 5 · Lesson 2 of 18 · Free

Variables & Basic Data Types

⏱ About 25 minutes · ▶ run real Python here — nothing to install · no sign-in

In this lesson you will

  • Store a value in a variable and print it
  • Change a variable and predict its new value
  • Tell an int, a float and a str apart with type()

In your school bag, every book has a name label on it. You open the bag, read the label, and find the right book. In Python, a variable is a labelled box that keeps a value safe until you need it.

What is a variable in Python?

A variable is a name that stores a value. Think of it as a box with a label on it.

You make a variable with one = sign. The name goes on the left and the value on the right.

Later, you just write the name. Python opens the box and uses the value inside.

🎬 How Python thinks — step 1 of 6Python is about to run line 1
▶name = "Riya"
2age = 10
3print(name)
4print(age)
5print(name, "is", age, "years old")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Riya
10
Riya is 10 years old

💡 Read = as "gets", not "equals". So name = "Riya" means: name gets the value "Riya".

How do I change the value of a variable?

A variable can hold only one value at a time. If you store a new value, the old one is thrown away.

That is why it is called a variable: its value can vary, or change.

Python can even use the old value to make the new one. Watch the score grow ball by ball.

🎬 How Python thinks — step 1 of 7Python is about to run line 1
▶score = 0
2print("Start:", score)
3score = 4
4print("After a four:", score)
5score = score + 6
6print("After a six:", score)
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Start: 0
After a four: 4
After a six: 10

💡 In score = score + 6, Python works out the right side first, then puts the answer back into score.

What are int, float and str in Python?

Every value has a type. The type tells Python what kind of value it is and what it can do.

An int is a whole number, like 10 or -3. A float is a number with a decimal point, like 4.5. A str (string) is text inside quotes.

The type() command tells you the type of any value. It is a handy way to check.

🎬 How Python thinks — step 1 of 7Python is about to run line 1
▶roll_number = 21
2height = 1.42
3city = "Nagpur"
4print(type(roll_number))
5print(type(height))
6print(type(city))
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
<class 'int'>
<class 'float'>
<class 'str'>

💡 Python decides the type by itself when you store the value. You do not need to tell it.

Why are 10 and "10" different in Python?

Quotes turn anything into text. So "10" is a string, even though it looks like a number.

Python can do maths with the int 10. But it treats "10" like a word, letter by letter.

10 and 10.0 have the same value. But one is an int, and the other is a float.

🐍 Python — you can edit this code
Output
<class 'int'>
<class 'str'>
<class 'float'>
15
10 + 5

What are the rules for naming variables?

A name can have letters, digits and the underscore _. It cannot start with a digit or contain spaces.

Names are case-sensitive, so Marks and marks are two different boxes. Most Python coders use small letters.

Choose names that explain the value. tiffin_item is much clearer than t or x.

🐍 Python — you can edit this code
Output
Kabir 92 14

💡 Use an underscore instead of a space: total_runs, not total runs.

Can one variable copy another?

Yes. When you write b = a, Python copies the value of a into b at that moment.

After that, the two boxes are separate. Changing a later does not change b.

🐍 Python — you can edit this code
Output
Today: 50
Yesterday: 40

🤔 Predict the output

Think like Python: read the code and choose what it prints. You get the reason straight away.

Question 1. What does this print?

x = 5
x = 8
print(x)

Question 2. What does this print?

price = 3.0
print(type(price))

Question 3. What does this print?

a = 4
b = a
a = 10
print(a, b)

🧩 Your challenge

Make a cricket player card. Store a player's name, age, runs and batting average in four variables. Print each one, then print the type of the batting average.

Expected output :
Player: Smriti
Age: 27
Runs: 3200
Average: 45.5
<class 'float'>
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

city = Pune
print(city)

NameError: name 'Pune' is not defined

✅ Right

city = "Pune"
print(city)

Without quotes, Python thinks Pune is a variable name. Text values need quotes.

❌ Wrong

2nd_place = "Ravi"
print(2nd_place)

SyntaxError: invalid decimal literal

✅ Right

second_place = "Ravi"
print(second_place)

A variable name cannot start with a digit. Start it with a letter instead.

❌ Wrong

marks = 90
print("marks")

No error – but it prints the word marks, not the number 90.

✅ Right

marks = 90
print(marks)

Quotes make a string. To use the variable's value, write its name without quotes.

📌 Remember

  • A variable is a named box that stores a value: name = value.
  • A variable keeps only its latest value; a new value replaces the old one.
  • int is a whole number, float has a decimal point, str is text in quotes.
  • type() tells you what type a value is.
  • Names use letters, digits and _, cannot start with a digit, and have no spaces.
  • Write the name without quotes to use the value inside the variable.

Finished the quiz and the challenge?

Questions students ask

What is a variable in Python for kids?

A variable is a name that stores a value, like a labelled box. You write age = 10, and later Python uses 10 whenever you write age.

What is the difference between int and float in Python?

An int is a whole number, like 7. A float has a decimal point, like 7.5 or even 7.0. Both are numbers, so you can do maths with them.

Can a variable name have spaces?

No. Use an underscore instead, like total_marks. A name also cannot start with a digit, and Python treats capital and small letters as different.

Do I have to tell Python the type of a variable?

No. Python works out the type from the value you store. Use type() any time you want to check it.