Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    PyPython

    Getting started

    • Your first Python program
    • Variables and types
    • Numbers and operators
    • Type conversion and input

    Strings

    • Strings and f-strings
    • String indexing and slicing
    • Cleaning and splitting strings

    Control flow

    • Conditions: if, elif and else
    • Loops: for and while
    • Loop control and nesting

    Functions

    • Functions with def
    • Parameters and scope

    Collections

    • Lists
    • Dictionaries
    • Tuples and sets
    • Comprehensions, enumerate and zip

    Errors, files and libraries

    • Handling exceptions
    • Modules and the standard library
    • Reading and writing files
    • Exchanging data with JSON

    Objects and lazy iteration

    • Classes and objects
    • Inheritance and composition
    • Iterators and generators

    Testing and project

    • Testing and project setup
    • Project: a grade report
    Python

    Control flow · Lesson 8 of 25

    Conditions: if, elif and else

    In Python indentation isn't style; it's part of the code.

    7 minutes3 games

    A condition ends with : and the code that belongs to it is indented (4 spaces). Python knows what belongs where from the indentation, not from brackets.

    Python
    temp = 28
    
    if temp > 35:
        print("Very hot")
    elif temp > 25:
        print("Warm")
    else:
        print("Cool")
    ToolUse

    == / !=

    Equal / not equal

    and

    Both conditions true

    or

    At least one condition true

    not

    Negate truth value

    Important

    Use == for comparison and = for assignment. An if/elif/else chain runs only the first matching branch.

    Interview question

    When should you use elif rather than another if?

    Forget the indentation or the : and you'll get an IndentationError or SyntaxError.

    Spot the bug

    One line will error. Which?

    Order the lines

    Order it: print even for even numbers, otherwise odd.

    1. Click the lines in the right order

    Exercise

    Print A if marks is 85 or more, otherwise B.

    Expected output: A

    Python
    marks = 91
    

    Learn more from

    • Python documentationdocs.python.org
    • Real Python: further readingrealpython.com

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousCleaning and splitting stringsNextLoops: for and while
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.