Python Operators
Python operators can be keywords or symbols that are used to perform operations on operands.
Arithmetic Operators in Python
Arithmetic operators are used to perform mathematical calculations in Python. There are 7 main arithmetic operators:
- Addition (
+) 2.Subtraction (-)3. Multiplication (*) 4. Division (/) 5.Modulus (%) 6. Floor Division (//) 7.Exponentiation / Power (**)
1. ADDITION (+)
The addition operator (+) is used to add two numbers together. When used with strings, it concatenates (joins) two strings together.
var = 3 + 7print(var)Output:
10 2. SUBTRACTION (-)
The subtraction operator (-) is used to subtract one number from another number.
var = 23 - 3print(var)Output:
20Exception: The subtraction operator cannot be used directly with strings.
var = "23" - "3"Output:
TypeError: unsupported operand type(s) for -: 'str' and 'strUnlike +, the - operator does not subtract or remove one string from another.
3. MULTIPLICATION (*)
The multiplication operator (*) is used to multiply one number by another number. It is an arithmetic operator in Python.
var = 2 * 2print(var)Output:
4Exception: You cannot multiply two strings together.
var = "Hello" * "WorldOutput:
TypeError: can't multiply sequence by non-int of type 'str'However, Python does allow a string to be multiplied by an integer:
var = "Hello" * 3
print(var)Output:
HelloHelloHello4. DIVISION (/)
The division operator (/) divides one number by another and always returns a float.
var = 20 / 2print(var)Output:
10.0Here, 10.0 is the result (note the .0 — / always gives a float, even if it divides evenly).
5. MODULUS / (%)
In Python arithmetic operations, the modulus operator (%) is used to find the remainder after dividing one number by another. It is not used to calculate percentages.
var = 20 % 3print(var)Output
Get Kumarbsai’s stories in your inbox
Join Medium for free to get updates from this writer.
Here, 2 is the remainder after dividing 20 by 3.
Percentage Calculation
To calculate a percentage in Python, you can use multiplication and division:
marks = 80
percentage = (marks / 100) * 100print(percentage)Important: % means modulus (remainder) in Python, not percentage.
6. FLOOR DIVISION (//)
Floor division is used to divide two numbers and return the whole-number result, without the decimal part.
var = 20 // 3print(var)Output:
6How does it work?
Normal division:
20 / 3Output:
6.666666666666667Floor division:
20 // 3Because 3 goes into 20 six complete times:
3 × 6 = 18The remaining 2 is ignored.
Remember: // means floor division. It returns the floor (greatest integer less than or equal to the result), so with negative numbers it can go to the next lower integer: -20 // 3 gives -7.
7. POWER OPERATOR (**)
The power operator in Python is used to raise a number to a specified power.
var = 2 ** 3print(var)Output:
8How does it work?
2 ** 3 means:
2 × 2 × 2So:
2 ** 3means 2 raised to the power of 3, which is 8.
If you want 16, you can use:
var = 2 ** 4print(var)output 16








