PythonMastery

Variables and print in Python

Store a name and an age in variables, then print them in one sentence with an f-string. Shows how variables and print() work together.

A variable is a name for a value. Once a value has a name, you can use it as many times as you like.

The program

python
name = "Ada"
age = 25

print(f"Name: {name}, Age: {age}")
output
Name: Ada, Age: 25

How it works

Try changing it

Change a variable and print again. The new value replaces the old one:

python
name = "Ada"
age = 25
age = age + 1

print(f"Next year {name} will be {age}.")
output
Next year Ada will be 26.

Learn the idea: Variables & Data Types, F-Strings: Modern String Formatting