Introduction to Operators Operators in Python are special symbols or keywords used to perform operations on variables and values.
Python has several types of operators:
Arithmetic Operators
Relational (Comparison) Operators
Logical Operators
Assignment Operators
Bitwise Operators
Arithmetic Operators Arithmetic operators are used to perform mathematical calculations.
Let us take two variables:
no1 = 10
no2 = 3
Operator Name Example Output
Addition no1 + no2 13
Subtraction no1 - no2 7
Multiplication no1 * no2 30 / Division no1 / no2 3.3333... // Floor Division no1 // no2 3 % Modulus no1 % no2 1 ** Exponentiation (Power) no1 ** no2 1000 Example:
no1 = 10
no2 = 3
print(no1 + no2)
print(no1 - no2)
print(no1 * no2)
print(no1 / no2)
print(no1 // no2)
print(no1 % no2)
print(no1 ** no2)
Important: Division by zero causes a ZeroDivisionError.
no1 = 10
no2 = 0
print(no1 / no2) # ZeroDivisionError
print(no1 // no2) # ZeroDivisionError
Variable Assignment and Multiple Variables Python allows…