Skip to content
techsnow

Python Basics

Variables

A variable is a name that stores a value. You create one by assigning with =. Python figures out the type for you.

Syntax:

name = "Ayesha"
age = 21
height = 5.4
is_student = True

print(name, age, height, is_student)

Output

Ayesha 21 5.4 True

Naming rules

  • Names can contain letters, digits and _, but cannot start with a digit.
  • They are case-sensitive: age and Age are different.
  • Use snake_case: first_name, total_price.
  • Don't use keywords like if, for, class or built-in names like list and print.

Multiple assignment

x, y, z = 1, 2, 3
a = b = 0
x, y = y, x   # swap two values