Last updated

Python Variables

Definition: A variable is a name that refers to a stored value — like a labelled box you can put a value into and read later. You create one with the equals sign =.

Example 1 — creating variables

x = 5
name = "Talented"
print(x)
print(name)

No keyword is needed — assigning a value creates the variable.

Example 2 — variables can change

You can reassign a variable any time, even to a different type of value:

score = 10
print(score)
score = score + 5
print(score)
score = "now I am text"
print(score)

Example 3 — assigning several at once

a, b, c = 1, 2, 3
print(a + b + c)

Naming rules

  • Must start with a letter or underscore (not a number)
  • Can contain letters, numbers, and underscores — no spaces
  • Case-sensitive: age and Age are different variables

💡 Tip: use descriptive names like user_age or total_price instead of x. Clear names make code read like a story.

Try it Yourself
Output

          
Ad · responsive