Python for Kids

Variables in Python

1. What is a Variable?

  • A variable stores information
  • It has a name and a value
  • Helps avoid repeating values

2. String Variable

Example:

name = "Spongebob"
print(name)
  • Quotes → string
  • Without quotes → variable

3. Using f-strings

  • f-strings mix text and variables

Example:

print(f"My name is {name}")

The text inside the curly bracket is a variable and will replace the value of the variable. For example name = "John"; so wherever you use name it will replace with John.

4. Integer Variable

age = 20
print(f"I am {age} years old")

Here age will replace 20 as the value of age is 20.

5. Float Variable

price = 10.99
print(f"Price is {price}")

6. Boolean Variable

is_student = True
print(is_student)

It will print True as the value of is_student variable is True. If it’s false then it will print False.

7. Summary

  • Variables store data
  • f-strings combine text & variables

8. Task

Create a profile card using:

  • Name (string)
  • Age (integer)
  • Height (float)
  • Student (boolean)