Skip to content

    Operators & Expressions

    Python · Beginner

    Definition

    Operators perform arithmetic (+ − * / // % **), comparison, logical (and/or/not) and membership (in).

    Every calculation and condition uses operators.

    Diagram

    7 // 2 = 37 % 2 = 12 ** 3 = 8

    Flowchart

    Choose operatorRespect precedenceUse parentheses for clarityEvaluate

    Example: Common operators

    print(7 / 2, 7 // 2, 7 % 2, 2 ** 3, 3 in [1, 2, 3])

    Output: 3.5 3 1 8 True

    Key points

    • // floors toward −∞
    • is checks identity, == checks equality

    Interview questions

    is vs ==?

    == compares values; is compares whether two names point to the same object.

    More Python topics