Sitemap
Kumarbsai

Kumarbsai

Python Operators

2 min readAug 28, 2026

--

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:

  1. 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 + 7
print(var)

Output:

10 

2. SUBTRACTION (-)

The subtraction operator (-) is used to subtract one number from another number.

var = 23 - 3
print(var)

Output:

20

Exception: The subtraction operator cannot be used directly with strings.

var = "23" - "3"

Output:

TypeError: unsupported operand type(s) for -: 'str' and 'str

Unlike +, 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 * 2
print(var)

Output:

4

Exception: You cannot multiply two strings together.

var = "Hello" * "World

Output:

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:

HelloHelloHello

4. DIVISION (/)
The division operator (/) divides one number by another and always returns a float.

var = 20 / 2
print(var)

Output:

10.0

Here, 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 % 3
print(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) * 100
print(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 // 3
print(var)

Output:

6

How does it work?

Normal division:

20 / 3

Output:

6.666666666666667

Floor division:

20 // 3

Because 3 goes into 20 six complete times:

3 × 6 = 18

The 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 ** 3
print(var)

Output:

8

How does it work?

2 ** 3 means:

2 × 2 × 2

So:

2 ** 3

means 2 raised to the power of 3, which is 8.

If you want 16, you can use:

var = 2 ** 4
print(var)output 16

--

--