Lesson 1, Topic 1
In Progress

Lesson 1.3 – Operators

Lesson 3 ยท Operators | Unit 1 ยท Knowledge Pillars
Unit 1 ยท Lesson 1.3 Building Blocks of Python

โž• Operators โ€” Do the Math (and More!)

Operators are the action buttons of Python โ€” they add, subtract, compare, and combine. Learn the critical difference between = and ==, and unlock the mystery of the % operator.

โฑ๏ธ 45 minutes
๐ŸŽฏ Objective 1
๐Ÿ Python ยท CodeSkills Lab
Lesson 1.3 โ€” Unit 1
๐Ÿง  Big Idea: An operator is a symbol that does something with your data. Think of operators like the buttons on a calculator โ€” except Python's operators can do a lot more than just math. They can compare values, combine text, and even check for leftovers!

๐Ÿ—‚๏ธ Key Terms First

New words in this lesson. Tap a card to flip it and see what each term means before you start practicing.

Math Operators

These work just like a calculator โ€” with two bonus operators you might not have seen before:

OperatorNameExampleResultPlain English
+Addition5 + 38Add
-Subtraction10 - 46Subtract
*Multiplication3 * 412Multiply
/Division15 / 35.0Divide (always gives a float!)
**Exponent2 ** 382 to the power of 3
%Modulo10 % 31Remainder after dividing
๐Ÿ” What is modulo (%)? It gives you the leftover after dividing. Think of it like sharing pizza: if you have 10 slices and 3 friends, each gets 3 slices (3 ร— 3 = 9) and there is 1 slice left over โ€” that leftover is what 10 % 3 gives you. Modulo is used all the time to check if a number is even or odd!
Python โ€” Math operators in action
health = 100
damage = 35
health = health - damage
print("Health:", health)      # 65

score = 50
bonus = 25
total = score + bonus
print("Total:", total)        # 75

print(10 % 2)   # 0  โ†’ 10 is even (no remainder)
print(11 % 2)   # 1  โ†’ 11 is odd (remainder of 1)
print(2 ** 8)   # 256 โ†’ used in computer memory sizes!

Comparison Operators

Comparison operators ask a question about two values. The answer is always True or False โ€” a boolean! These are what power every if/else decision in your programs.

OperatorMeaningExampleResult
==Is equal to?5 == 5True
!=Is NOT equal to?5 != 3True
>Is greater than?10 > 7True
<Is less than?3 < 1False
>=Greater than or equal?5 >= 5True
<=Less than or equal?4 <= 3False

The + Operator with Strings

The + operator doesn't just add numbers โ€” it can also join strings together. Combining strings is called concatenation (say it: con-CAT-en-AY-shun).

Python โ€” String concatenation
first_name = "Alex"
last_name = "Coder"

# Joining with + (don't forget the space in the middle!)
full_name = first_name + " " + last_name
print(full_name)   # Alex Coder

# f-strings do the same thing but are easier to read:
print(f"Hello, {first_name}!")   # Hello, Alex!
๐Ÿ’ก f-strings vs concatenation: Both work, but f-strings are cleaner for longer sentences. Use concatenation for quick joins, f-strings when you have a longer sentence with many variables mixed in.

๐Ÿงฎ Interactive Operator Explorer

Type two numbers, pick an operator, and see what Python would output โ€” right here on the page!

Operator Explorer โšก Try It Now
Left value:
Output โ†’ Press Calculate to see the result!

๐ŸŽฏ Predict the Output!

Read each code snippet and type what you think Python will print. Then click Check to see if you were right. No peeking โ€” try it in your head first!

x = 8 print(x % 3)
a = 5 b = 10 print(a == b)
score = 50 score = score + 25 print(score > 60)
name = "Code" print(name + "r")
print(2 ** 4)
print(15 % 4)

โŒจ๏ธ CodeSkills Lab Exercises

Exercise 3A โ€” Score Calculator ๐Ÿงช CodeSkills Lab

What to do: Build a mini game score calculator. Start with a score of 0, add points for three different actions, then print the final score and check whether it's over 100.

  1. Copy the starter code into your CodeSkills Lab
  2. Fill in the three action scores with numbers of your choice
  3. Run it and check that the output makes sense
  4. Add one more line using % to check if the final score is even or odd
Starter Code โ€” Copy into CodeSkills Lab
# Exercise 3A โ€” Score Calculator
score = 0

# Add points for three actions (choose your own values!)
score = score + 0    # Collected a coin
score = score + 0    # Defeated an enemy
score = score + 0    # Found a treasure chest

print("Final score:", score)
print("Score over 100?", score > 100)

# BONUS: Is your score even or odd?
# Add your modulo line here:
Exercise 3B โ€” Name Builder ๐Ÿงช CodeSkills Lab

What to do: Practice string concatenation and f-strings by building a personalized greeting. Use both methods and compare the output.

  1. Copy the starter code into your CodeSkills Lab
  2. Replace the placeholder names with your own first and last name
  3. Run it and confirm both print statements produce the same result
  4. Add a third line using an f-string that also prints your age
Starter Code โ€” Copy into CodeSkills Lab
# Exercise 3B โ€” Name Builder
first_name = "First"
last_name = "Last"
age = 0

# Method 1: Concatenation with +
greeting_concat = "Hello, " + first_name + " " + last_name + "!"
print(greeting_concat)

# Method 2: f-string
greeting_fstring = f"Hello, {first_name} {last_name}!"
print(greeting_fstring)

# Add your f-string with age below:

๐Ÿง  Lesson 3 Knowledge Check

Answer all three questions, then click Check Answers to see your score!

Lesson 3 Score: 0 / 3