Skip to content

Variables

Variables store values.

**Naming conventions: **

  • snake_case, camelCase, PascalCase.
  • Must start with a letter or underscore,
  • No spaces, No special characters except underscore[_]
  • Cannot use reserved keywords[e.g., if, else, while, for, def, class, etc.]
  • Variables are Case-sensitive
iq = 190
user_age = iq/4  # iq/4 is an expression, the line is called statement
a = user_age
print(a)

Constants

Constant Variable (by Convention, use uppercase letters) Permanent Value that should not be changed

PI = 3.14

Dunder

__ dunder (double underscore) methods and variables are reserved for special use in Python

_ single underscore (convention for "private" variables)

Multiple Assignment

a, b, c = 1, 2, 3 

Augmented Assignment Operators

+=, -=, =, /=, //=, %=, *=

a += 2      # equivalent to a = a + 2