✦ Python Foundations First lesson

Concept 01 · Variables

Give values a name.
Then make them useful.

Variables help a Python program refer to values clearly. Learn the idea, try it in the playground, then predict what changes.

01 Learn02 Try03 Predict

A variable is a name that refers to a value.

In Python, you create a variable by writing a name, an equals sign, and a value. The name gives your program a useful way to refer to that value later.

favorite_language = "Python"

Here, favorite_language refers to the string "Python". print() asks Python to show the value that the name currently refers to.

print(favorite_language) # Python

You can also assign a new value to the same name. After reassignment, print() uses the new value.

↳

Keep this in mind: A variable name is not a physical box. It is a label Python uses to refer to a value.

Tiny example
score = 10
print(score)

score = 15
print(score)

The output changes because score now refers to 15.

Python Playground

Loading Python runtime…

Edit the code, then run it in your browser. Nothing is sent to the Django server.

variables.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will Python print?

Read the code before running it. The name is assigned twice — which value does print() use each time?

message = "Hello"
print(message)

message = "Welcome"
print(message)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Ask Sloby about variables

Describe what feels unclear. Sloby will guide your thinking before giving an answer.

What would you like to understand about variables?

What will the program print, and why?

x = 10
y = x
x = 20

print(y)
Python AI Tutor · Learn by understanding, not just by running code.