Variables: Storing Information
A variable is essentially a labeled storage box in your computer's memory. You use the assignment operator (=) to assign a value to a variable.
python name = 'Alice' age = 30 is_student = False
Variable Naming Rules (Must Follow)
- Names must start with a letter (
a-z,A-Z) or an underscore (_). - Names cannot start with a number.
- Names can only contain alphanumeric characters and underscores (
A-z,0-9, and_). - Names are case-sensitive (
Ageis different fromage). - Names cannot be reserved keywords (like
print,if,for).
Naming Convention (Best Practice - PEP 8)
Python uses snake_case for variables and functions (all lowercase, words separated by underscores).
python
Good Practice
user_name = 'Bob' total_score = 95.5
Bad Practice
UserName = 'Cathy' # Use snake_case score-total = 10 # Cannot use hyphens