Variables
Variables are containers that store data values. In Python, you create a variable by assigning a value to a name.
Creating Variables
Loading Python Playground...
Variable Naming Rules
- Must start with a letter or underscore
- Can contain letters, numbers, and underscores
- Case-sensitive (
nameandNameare different) - Cannot be Python keywords (like
if,for,while)
Loading Python Playground...
Exercises
Loading Python Exercise...
Loading Python Exercise...
Loading Python Exercise...
Multiple Assignment
Loading Python Playground...
Swapping Variables
Loading Python Playground...
Loading Python Exercise...
Practice Playground
Loading Python Playground...
Key Takeaways
- Create variables with
=(assignment operator) - Use descriptive, snake_case names
- Variables can be reassigned
- Python allows multiple assignment:
a, b = 1, 2 - Swap values easily:
a, b = b, a

