DS 1501 · Lesson 4 of 24
Instructor: Corey Schafer16m
Sign in to watchWrite programs that inspect data conditions and take selective execution paths using booleans, truthiness, and if/elif/else control flow. What you will learn: • Boolean expressions, comparison operators, and Python truthiness (0, 0.0, '', [], None are falsy). • One-way (if), two-way (if/else), and multi-way (if/elif/else) branching blocks defined strictly by 4-space indentation. • Chained comparisons unique to Python (e.g., 60 <= score < 70 and ascending/descending traps like 23 >= number < 30). • Difference between independent if statements (multiple can execute) vs mutually exclusive if/elif chains (first True wins). • Short-circuit evaluation of and / or. University Outline Mapping: Class 4 · CO1 · Reading: 2.7, 3.5, 3.6 (Deitel), Chapter 5 (crash) · Activities: Lecture, Slides, Demonstration.
Note
Outline: Class 04 | CO1 | Reading: Deitel 2.7, 3.5, 3.6 & Crash Course Ch. 5 Midterm Chained-Comparison Spotlight: 23 >= x < 30 is evaluated as (23 >= x) and (x < 30)! Multiple if blocks vs elif: if x > 0: ... # tested independently if x > 10: ... # BOTH can run when x = 15 vs if x > 10: ... elif x > 0: ... # order matters: most specific first! Practice: Solve Lab Quiz 6, 7, 8 & 9 on CSECommunity.
Same resources as in the community course — sign in to watch the lesson and track progress.
Watch the whole course.
Sign in to play every lesson, track your progress, and ask questions alongside the community.
Already signed in? Open lesson in Community