Skip to content

Variables and Operators

Variables are containers for storing data values. In Python, a variable is created the moment you first assign a value to it.

Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.

x = 5
y = "Zavont"
print(x)
print(y)
  • A variable name must start with a letter or the underscore character.
  • A variable name cannot start with a number.
  • Variable names are case-sensitive (age, Age, and AGE are different variables).

Python divides the operators into the following groups:

Used with numeric values to perform common mathematical operations:

OperatorNameExample
+Additionx + y
-Subtractionx - y
*Multiplicationx * y
/Divisionx / y
%Modulusx % y
**Exponentiationx ** y

Used to assign values to variables:

x = 5 # Assign 5 to x
x += 3 # Same as x = x + 3

Used to compare two values:

x == y # Equal
x != y # Not equal
x > y # Greater than