Skip to content
doubtly

What are different math operators used in Python? Describe all different types of math operators used in Python.

What are different math operators used in Python?

Describe all different types of math operators used in Python. Also give an example for each.

Sagar S. Asked Updated Student doubt Save WhatsApp Report

2 answers

Best answer

Answer: Python has arithmetic, assignment, comparison (relational), logical, identity, membership and bitwise operators.

1. Arithmetic operators (take x = 13, y = 4 where useful)

OperatorMeaningExampleResult
+Addition3 + 58
-Subtraction5 - 32
*Multiplication2 * 48
/Division (always gives a float)13 / 43.25
//Floor division (rounds down)15 // 27 (and -15 // 2 gives -8)
%Modulus (remainder)5 % 21
**Exponent (power)2 ** 532

2. Assignment operators (start each with x = 5)

OperatorSame asResult
x = 5assign 5 to x5
x += 3x = x + 38
x -= 3x = x - 32
x *= 3x = x * 315
x /= 3x = x / 31.6666666666666667
x %= 3x = x % 32
x //= 3x = x // 31
x **= 2x = x ** 225

3. Comparison (relational) operators (x = 5, y = 3); each gives True or False

OperatorMeaningExampleResult
==Equal tox == yFalse
!=Not equal tox != yTrue
>Greater thanx > yTrue
<Less thanx < yFalse
>=Greater than or equal tox >= yTrue
<=Less than or equal tox <= yFalse

4. Logical operators (x = 5)

OperatorMeaningExampleResult
andTrue if both conditions are truex > 3 and x < 10True
orTrue if at least one condition is truex > 6 or x < 10True
notReverses the resultnot (x > 10)True

5. Identity operators: check whether two names refer to the same object in memory (use == to compare values). With a = [1, 2, 3]; b = a; c = [1, 2, 3]:

  • a is b gives True (same list object)
  • a is c gives False (equal values but two different lists), while a == c gives True
  • a is not c gives True

6. Membership operators (s = "Hello how are you ?")

  • in: "you" in s gives True
  • not in: "Hi" not in s gives True

7. Bitwise operators (a = 12 = 1100, b = 10 = 1010 in binary)

OperatorMeaningExampleResult
&AND: bit is 1 if both bits are 1a & b8 (1000)
|OR: bit is 1 if either bit is 1a | b14 (1110)
^XOR: bit is 1 if only one of the bits is 1a ^ b6 (0110)
~NOT: inverts all bits, ~a = -(a+1)~a-13
>>Right shifta >> 23
<<Left shift (fills zeros from the right)a << 248

Checked in Python 3

print(3 + 5, 5 - 3, 2 * 4, 13 / 4, 15 // 2, -15 // 2, 5 % 2, 2 ** 5)
x = 5; x += 3; print(x)
x = 5; x -= 3; print(x)
x = 5; x *= 3; print(x)
x = 5; x /= 3; print(x)
x = 5; x %= 3; print(x)
x = 5; x //= 3; print(x)
x = 5; x **= 2; print(x)
x, y = 5, 3
print(x == y, x != y, x > y, x < y, x >= y, x <= y)
x = 5
print(x > 3 and x < 10, x > 6 or x < 10, not (x > 10))
a = [1, 2, 3]; b = a; c = [1, 2, 3]
print(a is b, a is c, a == c, a is not c)
s = "Hello how are you ?"
print("you" in s, "Hi" not in s)
a, b = 12, 10
print(a & b, a | b, a ^ b, ~a, a >> 2, a << 2)
8 2 8 3.25 7 -8 1 32
8
2
15
1.6666666666666667
2
1
25
False True True False True False
True True True
True False True True
True True
8 14 6 -13 3 48
Doubtly · 16 Apr 2023 Report
Was this answer helpful?

Answer: Python's math (arithmetic) operators are + , − , * , / , // , % and ** .

OperatorNameExampleResult
+Addition3 + 58
-Subtraction7 - 34
*Multiplication3 * 412
/Division (always gives a float)13 / 43.25
//Floor division (rounds down)15 // 2
-7 // 2
7
-4
%Modulus (remainder)5 % 21
**Exponent (power)2 ** 532

Unary minus (-x) changes the sign of a number.

Each arithmetic operator also has an augmented assignment form that does the operation and stores the result: +=, -=, *=, /=, //=, %=, **=. For example, with x = 5, x += 3 makes x equal to 8.

Precedence: ** is done first, then * / // %, then + -. For example, 2 + 3 * 2 ** 2 = 2 + 3 × 4 = 14.

The earlier answer on this page gives 13 / 4 = 4.333; the correct result is 3.25 (4.333… is 13 / 3).

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.