Python Basics · Control Flow · Lesson 8 of 36
Comparison and Logic
Concept
Comparison and Logic
==, !=, <, and > compare values. and, or, and not combine conditions, spelled out instead of using symbols.
Chained comparisons like 0 < age < 18 also work in Python and read almost like plain English, unlike most other languages.
- Explain the core idea behind Comparison and Logic.
- Predict output before running a change.
- Test one realistic and one unusual input.
- Use the result to make the next decision.
- 1. Read one concept.
- 2. Change the example.
- 3. Run, compare, and explain.
- 4. Complete the challenge below.
Self-check before continuing
Without looking at the example, describe what changes when you modify one input in Comparison and Logic. Then reopen the editor and prove your explanation with a small test.
You are ready to continue when you can predict, test, and explain the result.
Your turn
Write a condition using or that checks if a day is Saturday or Sunday.
Ask about this lesson or your next move. The guide explains the path without taking the work away from you.
Ready for the next lesson?
Mark this lesson complete when you have finished the exercise.
Console