Programming FundamentalsNot Started
Variables & Assignment
How to store and name data in memory
0%
Explanation
A variable is a named label that points to a value stored in memory. When you write x = 5, Python reserves a spot in memory, stores the integer 5 there, and gives you the label x to refer to it.
Key ideas
- A variable stores a value — you read it by name, change it by reassigning
x = 10doesn't modify the old value — it makesxpoint to a new one- Python figures out the type from the value — no
int xdeclarations needed - Multiple variables can point to the same value:
a = b = 5
Naming rules
- ✓Must start with a letter or underscore:
name,_count,x1 - ✗Cannot start with a digit:
2fast - ✓Can contain letters, digits, and underscores only — no hyphens or spaces
- ✓Case-sensitive:
score,Score, andSCOREare three different variables - ✗Cannot use reserved keywords:
if,for,while,class,return…
Convention: use snake_case
python
user_name = "Alice" # ✓ Python convention
userName = "Alice" # ✗ camelCase (works but not Pythonic)Examples
Basic assignment
Assign different types of values to variables
x = 5
name = "Alice"
is_active = True
print(x, name, is_active) # 5 Alice TrueReassignment
A variable can be reassigned any number of times
score = 0
print(score) # 0
score = score + 10
print(score) # 10Next in Programming Fundamentals
Data Types