Skip to content
    Hack The FutureHack The FuturePython Notes

    UNIT 02 · TOPIC 08

    Identity Operators

    is and is not check whether two names refer to the same object; use == to compare values.

    The idea

    Identity Operators, simply explained

    is and is not check whether two names refer to the same object; use == to compare values.

    01

    See the big picture

    How the idea flows

    Input or goalIdentity OperatorsPython result
    Understand the problemApply Identity 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

    ↗

    Two identical-looking boxes can contain equal items while still being separate boxes.

    03

    Learn by doing

    Python code example

    PYTHONExample
    a = [1, 2]
    b = [1, 2]
    print(a == b, a is b)
    Expected resultTrue False
    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

    • is and is not check whether two names refer to the same object; use == to compare values.
    • Think of a real problem where identity 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 Identity Operators?

    is and is not check whether two names refer to the same object; use == to compare values.

    Where could you see this idea in everyday life?

    Two identical-looking boxes can contain equal items while still being separate boxes.

    Keep learning · Hack The Future