Area 2.4
Operators
Master arithmetic, relational, and Boolean operators for data manipulation and comparison. Learn operator precedence rules to write correct and efficient expressions.
3
Operator Types
16
Total Operators
~1.5hrs
Study Time
Learning Objectives
- Understand arithmetic operators for mathematical calculations
- Apply relational operators for comparisons between values
- Use Boolean operators for logical operations and decision making
- Know operator precedence rules and use parentheses effectively
- Combine different operator types in complex expressions
Operator Categories
Arithmetic Operators
Perform mathematical calculations on numeric values
+Addition5 + 3 = 8
Adding numbers, concatenating strings
-Subtraction10 - 4 = 6
Subtracting numbers, finding differences
*Multiplication6 * 7 = 42
Multiplying numbers, repeating strings
/Division15 / 3 = 5.0
Dividing numbers (always returns float)
//Floor Division17 // 5 = 3
Integer division (no remainder)
%Modulus17 % 5 = 2
Finding remainder after division
**Exponentiation2 ** 3 = 8
Raising to power, square roots
Python Examples:
# Arithmetic operations
result = 10 + 5 * 2 # 20 (multiplication first)
area = length * width
remainder = 17 % 5 # 2
power = 2 ** 8 # 256
average = total / count
# String operations
greeting = "Hello" + " " + "World" # Concatenation
repeated = "Hi! " * 3 # "Hi! Hi! Hi! "Relational Operators
Compare values and return True or False results
==Equal to5 == 5 → True
Check if values are the same
!=Not equal to5 != 3 → True
Check if values are different
<Less than3 < 5 → True
Check if left value is smaller
>Greater than7 > 4 → True
Check if left value is larger
<=Less than or equal5 <= 5 → True
Check if left ≤ right
>=Greater than or equal8 >= 6 → True
Check if left ≥ right
Python Examples:
# Relational comparisons
age = 18
is_adult = age >= 18 # True
is_child = age < 13 # False
password = "secret123"
is_correct = password == "secret123" # True
is_wrong = password != "wrong" # True
score = 85
passed = score >= 60 # TrueBoolean Operators
Combine logical conditions using AND, OR, and NOT
andLogical ANDTrue and False → False
Both conditions must be true
orLogical ORTrue or False → True
At least one condition must be true
notLogical NOTnot True → False
Reverses the boolean value
Truth Table:
| A | B | A and B | A or B |
|---|---|---|---|
| True | True | True | True |
| True | False | False | True |
| False | True | False | True |
| False | False | False | False |
Python Examples:
# Boolean operations
age = 20
has_license = True
# AND - both must be true
can_drive = age >= 18 and has_license # True
# OR - at least one must be true
eligible = age >= 65 or income < 30000 # depends on income
# NOT - reverses boolean
is_minor = not (age >= 18) # False
# Complex conditions
if (score >= 90 and attendance >= 0.8) or extra_credit:
grade = "A"Operator Precedence Rules
Remember: PEMDAS + Logical
Parentheses → Exponents → Multiplication/Division → Addition/Subtraction → Comparisons → NOT → AND → OR
1
Parentheses - highest priority
()(2 + 3) * 4 = 202
Exponentiation
**2 ** 3 * 4 = 323
Multiplication and Division
*, /, //, %2 + 3 * 4 = 144
Addition and Subtraction
+, -2 * 3 + 4 = 105
Relational comparisons
<, <=, >, >=, ==, !=2 + 3 < 10 → True6
Boolean NOT
notnot 5 < 3 → True7
Boolean AND
andTrue and 5 > 3 → True8
Boolean OR - lowest priority
orFalse or 2 == 2 → TrueLearning Activities
Operator Precedence Challenge
Calculation
30 minutes
Evaluate complex expressions following correct order of operations
Boolean Logic Workshop
Logic
40 minutes
Create complex conditional statements using AND, OR, and NOT operators
Expression Building Exercise
Translation
35 minutes
Translate word problems into mathematical and logical expressions