Python Lesson 4: Operators

PYTHON

AllComputerss

4/18/20261 min read

python tutorials
python tutorials

Operators are special symbols in Python that allow you to perform operations on variables and values. They are the building blocks for calculations, comparisons, and logical decisions in your programs.

Types of Operators
1. Arithmetic Operators

Used for basic mathematical operations:

x = 10

y = 3

print(x + y) # Addition → 13

print(x - y) # Subtraction → 7

print(x * y) # Multiplication → 30

print(x / y) # Division → 3.333...

print(x % y) # Modulus → 1

print(x ** y) # Exponentiation → 1000

2. Comparison Operators

Used to compare values, returning True or False:

print(x == y) # Equal → False

print(x != y) # Not equal → True

print(x > y) # Greater than → True

print(x < y) # Less than → False

print(x >= y) # Greater or equal → True

print(x <= y) # Less or equal → False

3. Logical Operators

Used to combine conditional statements:

print(x > 5 and y < 5) # True (both conditions are true)

print(x > 5 or y > 5) # True (one condition is true)

print(not(x > 5)) # False (negates the condition)

4. Assignment Operators

Used to assign values to variables:

z = 5

z += 3 # Equivalent to z = z + 3 → 8

z *= 2 # Equivalent to z = z * 2 → 16

5. Membership Operators

Check if a value is part of a sequence:

numbers = [1, 2, 3, 4]

print(2 in numbers) # True

print(5 not in numbers) # True

6. Identity Operators

Check if two variables point to the same object:

a = [1, 2]

b = [1, 2]

print(a is b) # False (different objects with same values)

print(a is not b) # True

Conclusion

Operators are essential for writing any meaningful Python program. They allow you to perform calculations, make decisions, and control the flow of your code. By mastering arithmetic, comparison, logical, and other operators, you’ll be able to build more complex and functional programs.

© 2026 AllComputerss. All rights reserved.