Variables

What Are Variables?

Variables are containers that store data. Think of them as labeled boxes — you give the box a name, and put a value inside it. In Python, you create a variable simply by assigning a value with =.
python
name = "Alice"
age = 25
is_student = True

print(name)
print(age)
print(is_student)

Variable Naming Rules

Variable names must start with a letter or underscore, can contain letters, numbers, and underscores, and are case-sensitive. Python convention uses snake_case for variable names.
python
my_name = "Bob"       # Good - snake_case
first_name = "Alice"  # Good
_private = 42         # Good - starts with underscore
# 2nd_name = "X"     # Bad - starts with number

Tip:Python is dynamically typed — you don't need to declare a variable's type. Python figures it out automatically!

PlaygroundPython
Output
Click "Run" to see output

💬 Got questions? Ask me anything!