Understanding Python Variables: A Beginner-Friendly Guide

Lets Learn Python!

Learning to code starts with understanding how programs remember information. In Python, this happens through something called variables. In this lesson, we’ll break down what variables are, why they matter, and how you can start using them in your own projects. Whether you’re curious about how a game keeps track of your score or how apps store user data, this guide will help you grasp the basics with clear examples.

python variables for beginners learning

What Are Variables in Python?

Think of a variable as a labeled box you create in your computer’s memory to store something—like a number or a piece of text. For example, you could have a box labeled age that holds the value 12. Any time your program needs to know your age, it simply looks inside that box.

In Python, you create a variable by assigning it a name and a value:

name = "Mauro"
age = 12

Here, name stores the text “Mauro”, and age stores the number 12. Text data like this is called a string Remember: strings must be surrounded by quotes, but numbers don’t use quotes.

Printing and Using Variables

After you create variables, you’ll often want to see what’s inside them. That’s where the print() function comes in:

print(name)
print(age)

This code outputs:

Mauro
12

You can also combine text and variables in one line to make it more readable:

print("Hi, my name is", name, "and I am", age, "years old.")

This prints:

Hi, my name is Mauro and I am 12 years old.

If you leave out print(), Python won’t display anything, so always use print() when you want output.

Working with Numbers, Strings, and Floats

Variables can store different types of data:

  • Strings (text): surrounded by quotes color = "blue"
  • Integers (whole numbers): no quotes score = 100
  • Floats (decimals): no quotes height = 1.75

These types let you create more dynamic programs, such as tracking scores, recording measurements, or displaying messages.

A Quick Challenge: Putting It All Together

Here’s an example you can try yourself. This script stores your name, hobby, and age, then prints a sentence with all three:

name = "Mauro"
hobby = "coding"
age = 12

print("Hi, my name is", name, "I love", hobby, "and I am", age, "years old.")

Running this code will display:

Hi, my name is Mauro I love coding and I am 12 years old.

When combining strings and numbers, you can use commas inside print() to separate them. This keeps your output clean and prevents errors.


Summary:
Today, you learned how to create and use variables in Python. Think of them as labeled containers that store important information for your programs. You now know how to declare variables, print their values, and combine them into sentences. As you keep learning, variables will become one of your most useful tools.

Please see my video below!



Ready to learn more?
Subscribe to Learn to Hack and Code on YouTube, and check out our other lessons to keep leveling up your skills!