Variables

Python SELF EN
Level 1 , Lesson 4
Available

1. Variables and Boxes

Variables are these special things for storing data. Like, any kind of data. All data in Python is stored using variables. A variable is kinda like a box. A regular, everyday box.

So, let's say you wrote down the number 13 on a piece of paper and put that piece of paper in a box. Now we can say “the box stores the value 13”.

Every variable in Python has two important properties: a name and a value.

The name is used to tell one variable apart from another. Kinda like a label on the box.

The value is some kind of object, data, or info stored inside the variable.

Every object in Python has its own type. For example, there might be types like “integer,” “float,” “text,” “cat,” “house,” and so on. However, a variable (box) itself doesn’t have a type. You can put an object of any type into the box. Same as in real life.

2. Creating Variables

In Python, there's no need to explicitly declare variables. You just write something like this:


name = value

The equals sign here isn't math's “equals.” It’s actually an assignment operator.

In other words, the equal symbol is like a command that says you gotta set (or assign) the value value to the variable named name.

Let's check out some examples:

name = "Alexander" Variable name contains a value — a string with the text “Alexander”
age = 35 Variable age contains a value — an integer 35
city = "London" Variable city contains a value — a string with the text “London”
pi = 3.14 Variable pi contains a value — a floating number 3.14

In Python you can assign any value to any variable. A variable doesn’t have a predefined type, only the type of the object it currently holds.

3. Expressions and Operators

On the left-hand side of the assignment sign, there gotta be a variable name. But the right-hand side can be an expression of any complexity.

name = "Alex" + "Alex" Variable name contains a value — a string with the text "AlexAlex"
age = 5 * 7 Variable age contains a value — the number 35
age = age * 2 + 3 Variable age contains a value — the number 73
age = age + 1 Variable age contains a value — the number 74

You can join two strings using the "+" sign. This operation is called concatenation. But you can only join string with string. In languages like Java or JavaScript, you could "sum" a string and a number. Not in Python: you gotta explicitly convert the number to a string first and then "add" it to the string.

Also, notice that the variable age appears on both sides of the assignment operator. That’s 'cause assignment isn’t equality, like in math.

Let’s look at this command:


age = age + 1    

It’s got two parts:

  1. Calculate the value of expression age + 1, using the current value of age;
  2. Save the result of that calculation into the variable age.

That command increases the value of the age variable by 1.

The order of operations is pretty much like math:

  • First, do whatever's in the parentheses;
  • Then go for multiplication and division;
  • And at the end — addition and subtraction.
3
Task
Python SELF EN, level 1, lesson 4
Locked
Age is just a number
Age is just a number
Comments (6)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Anonymous #11745494 Level 1, -, Liberia
8 January 2026
This is great, can't wait to explore more
Anonymous #11740823 Level 1, Groningen, Netherlands
20 December 2025
w this is so fun
Anonymous #11652172 Level 40, Montreal, Canada
13 May 2025
i need help
ogbe B. Lawson Level 2, Nigeria
8 May 2025
The interface is friendly to use
Socrates Level 2, France, France
15 March 2025
The current date is 2025 !!!
Benjamin Joseph Lentine Level 8, Songwon, South Korea
30 January 2025
I would recommend that you don't use words like "gotta" or "'cause". I get that it is supposed to read more conversationally, but it makes it feel unprofessional and could bring into question the quality of the course.