โž•
โญ Module 3 of 12 ยท Python for Beginners

Operators
in Python

Operators are the action words of programming โ€” they tell Python what to do with your data. Master them and your code comes alive!

๐Ÿ“– 6 Lessons ๐Ÿงฎ Live Calculator โœ๏ธ 3 Exercises ๐Ÿง  5 Questions
โž•
Arithmetic
Add, subtract, multiply, divide
โš–๏ธ
Comparison
Compare values
๐Ÿ”—
Logical
Combine conditions
๐Ÿ“‹
Precedence
Order of operations
โœ“
Variables & Data Types (Module 2)
Arithmetic Operators
Perform mathematical calculations on numbers.
OperatorNameExampleResult
+Addition10 + 313
-Subtraction10 - 37
*Multiplication10 * 330
/Division10 / 33.333โ€ฆ
//Floor Division10 // 33
%Modulus10 % 31
**Exponentiation2 ** 8256
arithmetic.py
a, b = 17, 5
print(a + b) # 22
print(a - b) # 12
print(a * b) # 85
print(a / b) # 3.4
print(a // b) # 3
print(a % b) # 2
print(a ** b) # 1419857
22
12
85
3.4
3
2
1419857

๐Ÿ”ต Modulus Visualizer โ€” See the remainder

Divide by
๐Ÿ’ก
The modulus operator % gives you the remainder. Great for checking if a number is even: n % 2 == 0!
Live Python Calculator
Try every operator โ€” see the Python expression and result in real time.
0

๐Ÿ“œ Python Equivalent

print(0)   # 0

๐Ÿ“Š History

Comparison Operators
Compare values โ€” always return True or False.
OperatorMeaningExampleResult
==Equal to5 == 5True
!=Not equal5 != 3True
>Greater than10 > 3True
<Less than3 < 10True
>=Greater/equal5 >= 5True
<=Less/equal4 <= 5True

โš–๏ธ Interactive Comparison

a =b =
โš ๏ธ
Don't confuse = (assignment) with == (comparison)!
Logical Operators
Combine conditions โ€” and, or, not.
๐Ÿค

and

True only if both are True

True and True โ†’ True
๐Ÿ”€

or

True if at least one is True

True or False โ†’ True
๐Ÿ”„

not

Flips the value

not True โ†’ False
logical.py
age = 20
score = 85
print(age >= 18 and score >= 80)
print(age >= 18 or score >= 90)
True
True
Operator Precedence & Shorthand
Order of operations and augmented assignments.
1
( )
Parentheses
2
**
Exponent
3
* / // %
Multiply/Divide
4
+ -
Add/Subtract
5
== != < > <= >=
Comparisons
6
not
Logical NOT
7
and
Logical AND
8
or
Logical OR
x += 5
โ†“
x = x + 5
x -= 3
โ†“
x = x - 3
x *= 2
โ†“
x = x * 2
x /= 4
โ†“
x = x / 4
x //= 3
โ†“
x = x // 3
x %= 7
โ†“
x = x % 7
Coding Exercises
โญ Exercise 1
Odd or Even
Use the modulus operator to check if 47 is odd/even.
n = 47
print(f"{n} is {'even' if n % 2 == 0 else 'odd'}") # odd
โญ Exercise 2
Voter Eligibility
Check if age >= 18 AND is_citizen = True.
age, is_citizen = 20, True
can_vote = age >= 18 and is_citizen # True
โญ Exercise 3
Predict the Output
Predict: 3 + 4 * 2, (3+4)*2, 2**3**2, 15%4, True and False or True
# 11, 14, 512, 3, True
Test Your Knowledge
Question 1 of 5
๐ŸŽ‰
5/5
5
Correct
0
Wrong
โž•
Module 03 โ€” Complete

Operators Mastered! ๐ŸŽ‰

You can now perform calculations, comparisons, and logical operations.

โœ“ Arithmetic
โœ“ Comparison
โœ“ Logical
โœ“ Precedence
โœ“ Shorthand

Next up: Module 4 โ€” Conditionals