Welcome to your first Python lesson! Today we're going to learn about variables - think of them as magical boxes that can store anything you want: numbers, words, or even your favorite things. By the end of this lesson, you'll be creating your own variables like a pro!
What is a Variable?
Imagine you have a box with a label on it. The label is the variable's name, and whatever you put inside is its value. In Python, we create variables like this:
my_age = 10
my_name = "Alex"
favorite_number = 7
That's it! You just created three variables. 'my_age' holds the number 10, 'my_name' holds the text "Alex", and 'favorite_number' holds 7. Python remembers these values so you can use them later in your program.
Naming Your Variables
Just like naming a pet, there are some rules for naming variables:
✅ Use lowercase letters: my_score
✅ Use underscores for spaces: player_name
✅ Make names meaningful: age (not just 'a')
❌ Don't start with numbers: 1player (wrong!)
❌ No spaces: my score (wrong!)
❌ No special characters: my@score (wrong!)
Good variable names help you and others understand your code!
Types of Variables
Python has different types of variables:
🔢 Numbers (integers): age = 12, score = 100
🔢 Decimal numbers (floats): height = 4.5, price = 9.99
📝 Text (strings): name = "Sam", city = "Mumbai"
✅ True/False (booleans): is_happy = True, game_over = False
Python is smart - it figures out the type automatically when you create a variable!
Try It Yourself!
Open Python and try creating these variables:
# About you
your_name = "Your Name Here"
your_age = 10
favorite_color = "blue"
loves_coding = True
# Print them out
print("Hello, my name is", your_name)
print("I am", your_age, "years old")
print("My favorite color is", favorite_color)
Run this code and see what happens! Change the values to make it about you.
Congratulations! You've learned about variables - one of the most important concepts in programming. Variables are used in every single program ever written, from simple calculators to video games. In our next lesson, we'll learn how to do math with variables and create a simple calculator. Keep practicing and remember: every expert coder started exactly where you are now!
A
Aarav Sharma
Age 11 · India · Coding Builder
Share this post
