beginnerBasics
Variables & Assignment
Understanding variables, naming rules, and assignment in Python.
In this lesson
01Creating Variables
In Python, variables are created when you assign a value to them. You do not need to declare a type — Python figures it out automatically (dynamic typing).
Python
1name = "Alice"2age = 253height = 5.64is_student = True56print(name, age, height, is_student)
Output
Alice 25 5.6 True
02Naming Rules
Variable names must start with a letter or underscore, can contain letters, numbers, and underscores, and are case-sensitive. Reserved keywords (like if, for, class) cannot be used as variable names.
Python
1# Valid names2my_var = 103_private = 204camelCase = 3056# Invalid names (will cause errors)7# 2fast = 10 <- starts with number8# my-var = 20 <- contains hyphen9# class = 30 <- reserved keyword
03Multiple Assignment
Python allows you to assign values to multiple variables at once:
Python
1x, y, z = 1, 2, 32a = b = c = 034print(x, y, z) # 1 2 35print(a, b, c) # 0 0 0
Output
1 2 3 0 0 0