Python Operators

1. What is an Operator?

An operator is a symbol that tells Python to do some work.

Example:

  • Add numbers

  • Compare values

  • Check True or False

2. Types of Operators in Python

Python has different kinds of operators.
Beginners should learn these first:

  1. Arithmetic Operators

  2. Assignment Operators

  3. Comparison Operators

  4. Logical Operators

3. Arithmetic Operators

(Used for math)

Addition (+)

a = 10
b = 5
print(a + b)

Subtraction (-)

print(a - b)

Multiplication (*)

print(a * b)

Division (/)

print(a / b)

Modulus (%) – Remainder

print(10 % 3)

Power (**)

print(2 ** 3)

Floor Division (//)

print(10 // 3)

4. Assignment Operators

(Used to give value)

Simple Assignment (=)

x = 10

Add and Assign (+=)

x = 5
x += 3
print(x)

Subtract and Assign (-=)

x = 10
x -= 4
print(x)

Multiply and Assign (*=)

x = 5
x *= 2
print(x)

5. Comparison Operators

(Used to compare values)

These operators return True or False.

Equal (==)

print(5 == 5)

Not Equal (!=)

print(5 != 3)

Greater Than (>)

print(10 > 5)

Less Than (<)

print(3 < 1)

Greater Than or Equal (>=)

print(5 >= 5)

Less Than or Equal (<=)

print(4 <= 2)

6. Logical Operators

(Used with True / False)

AND (and)

age = 20
print(age > 18 and age < 30)

OR (or)

print(age < 18 or age > 60)

NOT (not)

is_raining = False
print(not is_raining)

7. Operator with User Input

Example

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Sum:", a + b)
print("Is a greater?", a > b)

8. Common Beginner Mistakes

❌ Using = Instead of ==

if a = b:

✔ Correct:

if a == b:

❌ Forgetting Type Conversion

a = input("Enter number: ")
print(a + 5)

✔ Correct:

a = int(input("Enter number: "))
print(a + 5)

9. Simple Practice Examples

Example 1: Calculator

x = 20
y = 4

print(x + y)
print(x - y)
print(x * y)
print(x / y)

Example 2: Check Age

age = 17

print(age >= 18)

Example 3: Login Check

user = "admin"
pwd = "123"

print(user == "admin" and pwd == "123")

10. Summary (Python Operators)

✔ Operators do work in Python
✔ Arithmetic operators for math
✔ Comparison operators give True/False
✔ Logical operators check conditions
✔ Assignment operators update values

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • if–else statements

  • Loops (for, while)

  • Operator Exercises

  • MCQs with answers

Just tell me 😊

You may also like...