Python Mastery – From Basics to Brilliance / Operators in Python

Arithmetic Operators

These are used to perform basic math operations like adding, subtracting, multiplying, dividing, and more. Think of them like the symbols you use in regular math — but in a way Python understands!


Operator

Symbol

Example

What It Does

Addition

+

a + b

Adds two numbers

Subtraction

-

a - b

Subtracts second number from the first

Multiplication

*

a * b

Multiplies two numbers

Division

/

a / b

Divides and gives result with decimals (float)

Floor Division

//

a // b

Divides and gives the whole number only (ignores decimal part)

Modulus

%

a % b

Gives the remainder after division

Exponentiation

**

a ** b

Raises one number to the power of another (like a to the power b)


💡 Example:

➕ Addition (+)

a = 10
b = 5
result = a + b
print(result)  # Output: 15

👉 Adds 10 and 5.

➖ Subtraction (-)

a = 10
b = 5
result = a - b
print(result)  # Output: 5

👉 Subtracts 5 from 10.

✖️ Multiplication (*)

a = 4
b = 6
result = a * b
print(result)  # Output: 24

👉 Multiplies 4 and 6.

➗ Division (/)

a = 15
b = 2
result = a / b
print(result)  # Output: 7.5

👉 Divides 15 by 2 and gives decimal result.

🔢 Floor Division (//)

a = 15
b = 2
result = a // b
print(result)  # Output: 7

👉 Divides 15 by 2 and gives only the whole number part.

🔁 Modulus (%)

a = 15
b = 4
result = a % b
print(result)  # Output: 3

👉 15 divided by 4 leaves a remainder of 3.

⏫ Exponentiation (*)

a = 2
b = 3
result = a ** b
print(result)  # Output: 8

👉 2 raised to the power of 3 (2 × 2 × 2).