🎓 All Courses | 📚 Python Programming Syllabus

📋 Study this course on TaskLoco
⚡ Key Concept #python-programming#conditionals#control-flow

Conditionals — Control Flow

age = 18

if age >= 18:
    print("Adult")
elif age >= 13:
    print("Teenager")
else:
    print("Child")

Comparison operators:

==  # equal
!=  # not equal
>   # greater than
<   # less than
>=  # greater or equal
<=  # less or equal

Logical operators:

if age >= 18 and age < 65:
    print("Working age")

if name == "Alice" or name == "Bob":
    print("Known user")

if not is_banned:
    print("Welcome")

Ternary (one-liner):

status = "adult" if age >= 18 else "minor"

Truthy/Falsy: Empty string, 0, None, empty list/dict/set are all False. Everything else is True. This enables: if my_list: instead of if len(my_list) > 0:


YouTube • Top 10
Python Programming: If Statements & Conditionals
Tap to Watch ›
📸
Google Images • Top 10
Python Programming: If Statements & Conditionals
Tap to View ›

Reference:

Wikipedia: Conditional

image for linkhttps://en.wikipedia.org/wiki/Conditional_(computer_programming)

📚 Python Programming — Full Course Syllabus
📋 Study this course on TaskLoco

TaskLoco™ — The Sticky Note GOAT