PyPyPath

Module 2: Python Basic Syntax and Data Types

Variables

A variable is like a labeled box. You put a value inside, and later you can use the label to get that value back.

About 10 minutes

Creating variables

Use a name, then = , then a value. The name should describe what you store (e.g. age, name, score).

Example code
name = "Asha"
age = 20
print(name)
print(age)
Variables are labeled boxes

name

"Asha"

age

20

Changing a variable

You can put a new value in the same box anytime. The old value is replaced.

Example code
score = 10
print(score)
score = 15  # updated!
print(score)
  • Names use letters, numbers, underscore — no spaces.
  • Start with a letter or underscore (not a number).
  • Python is case-sensitive: Age and age are different.
Practice

Create variables for your city and a number you like. Print both. Then change the number and print again.

Key takeaways

  • Variables store values under a name.
  • Use = to assign or update a value.
  • Pick clear names like total_score, not x.

Quick check: Variables

Question 1 of 2

What does x = 5 do?