Skip to content
    Hack The FutureHack The FuturePython Notes

    UNIT 02 · TOPIC 07

    Membership Operators

    in and not in check whether a value occurs in a sequence or collection.

    The idea

    Membership Operators, simply explained

    in and not in check whether a value occurs in a sequence or collection.

    01

    See the big picture

    How the idea flows

    Input or goalMembership OperatorsPython result
    Understand the problemApply Membership OperatorsRun the codeCheck the output

    Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.

    02

    Everyday connection

    Real-life example

    ↗

    A ticket checker asks whether a seat number appears in the booked-seat list.

    03

    Learn by doing

    Python code example

    PYTHONExample
    booked = ['A1', 'A2', 'B1']
    print('A2' in booked)
    Expected resultTrue
    Try it: Change one value in the code, predict what will happen, then run it and compare your answer.
    04

    Keep this in mind

    Key takeaways

    • in and not in check whether a value occurs in a sequence or collection.
    • Think of a real problem where membership operators could save time or organize information.
    • Test small changes and read the result carefully before moving to a bigger program.

    Quick self-check

    Can you explain it in your own words?

    What is the main idea of Membership Operators?

    in and not in check whether a value occurs in a sequence or collection.

    Where could you see this idea in everyday life?

    A ticket checker asks whether a seat number appears in the booked-seat list.

    Keep learning · Hack The Future