Blog Playground Services About Contact
python

Variables in Python

August 2, 2026 · #python#beginners#variables

Variables are one of the first ideas you meet in Python. They let you store values and reuse them later — numbers, text, lists, and more.

Think of a variable as a labeled box. You put something in the box, give it a name, and use that name whenever you need the value.

Creating a variable

In Python you create a variable by writing a name, an equals sign, and a value:

age = 25
name = "Ada"

You don’t need to declare a type. Python figures it out from the value.

Try it: store and print values

Edit the code if you like, then click Run:

python

Naming rules (keep these in mind)

Good variable names make your code easier to read.

Do:

Don’t:

Examples:

Valid Invalid
score 2score
user_name user-name
total total amount

Changing a variable

You can update a variable by assigning a new value:

count = 1
count = count + 1

Or more briefly:

count = 1
count += 1

Try it: update a value

python

Common types you’ll use early

Type Example Meaning
int age = 21 Whole number
float price = 9.99 Decimal number
str city = "Lagos" Text
bool is_active = True True or False

Check a type with type():

x = 42
print(type(x))

Try it: inspect types

python

Quick practice

Before you move on, try changing the examples above:

  1. Change name to your own name and run again
  2. Start score at 0 and add points in two steps
  3. Create a variable for your favorite language and print it

What’s next

Once variables feel comfortable, the next step is working with strings and numbers — combining text, doing math, and formatting output cleanly.

For a broader learning path, see:


Whether you have a question, an idea, or feedback, we’d love to hear from you. Get in touch.