Lesson 6 – Operators

Operators are symbols that tell Python to perform an action. They allow you to add numbers, compare values, or make decisions inside your program. This lesson explains arithmetic operators, comparison operators, and simple examples for beginners.

Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations.

Example 1: Basic arithmetic operations

x = 10
y = 3

print(x + y)   # Addition
print(x - y)   # Subtraction
print(x * y)   # Multiplication
print(x / y)   # Division
print(x % y)   # Remainder
        

Output:

13
7
30
3.3333333333333335
1
        

Explanation:

Python performs each calculation step by step. The last line shows the remainder when 10 is divided by 3, which is 1.

Example 2: Exponent and floor division

print(2 ** 4)     # Exponent (2 to the power of 4)
print(17 // 5)    # Floor division (division without decimals)
        

Output:

16
3
        

Comparison Operators

Comparison operators check whether values are equal, greater, or smaller. They always return True or False.

Example 3: Comparing values

print(10 == 5)   # Equal to?
print(10 > 5)    # Greater than?
print(10 != 3)   # Not equal to?
print(4 <= 4)    # Less than or equal to?
print(8 >= 2)    # Greater than or equal to?
        

Output:

False
True
True
True
True
        

Why Operators Matter

Operators make your programs interactive and powerful. You can calculate totals, compare results, control decisions, and build logic for real applications.


Quiz: Test Your Understanding

1. What does the + operator do?

Divides numbers
Adds numbers
Compares numbers
Finds remainder
Correct answer: Adds numbers

2. What is the result of 9 % 4?

1
2
4
9
Correct answer: 1

3. What does 5 ** 2 mean?

5 × 2
5 minus 2
5 raised to the power 2
5 divided by 2
Correct answer: 5 raised to the power 2

4. What is the output of 17 // 5?

3.4
3
2
5
Correct answer: 3

5. What does == check?

If two values are equal
If two values are added
If one value is doubled
If values are printed
Correct answer: If two values are equal

6. Which operator gives a True or False result?

*
//
>
+
Correct answer: >

7. What does != mean?

Equal
Not equal
Add
Multiply
Correct answer: Not equal

8. What is the output of 10 > 3?

7
True
False
13
Correct answer: True

9. Which operator gives the remainder?

+
*
%
//
Correct answer: %

10. What is the output of 4 == 4?

8
False
True
Error
Correct answer: True
Back to Top