Back to course

Understanding Variables and Basic Naming Rules

Python Programming: The 0 to Hero Bootcamp

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)

  1. Names must start with a letter (a-z, A-Z) or an underscore (_).
  2. Names cannot start with a number.
  3. Names can only contain alphanumeric characters and underscores (A-z, 0-9, and _).
  4. Names are case-sensitive (Age is different from age).
  5. 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