← Python from Scratch Lesson 21 of 78 · 10 XP

Operators

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

An operator is a symbol that does something with values. You already know the arithmetic ones (+ - * / // % **). Here are the other groups:

Comparisons — give True or False: ==, !=, <, >, <=, >=.

Logical: and, or, not.

Augmented assignment — a short form:

x = 10
x += 5     # the same as x = x + 5  → 15
x -= 3     # 12
x *= 2     # 24

Membership — whether a value is inside:

"z" in "banana"       # False
"an" in "banana"      # True
3 in [1, 2, 3]        # True
5 not in [1, 2, 3]    # True

Identity — is checks that it is the very same object. It's used mostly for None: x is None.

The order of operations is as in maths: first **, then * / // %, then + -, then comparisons, then not, and, or. When in doubt, use parentheses.

Task. Read three segment lengths (each on its own line). Print True if they can form a triangle and False if they can't. A triangle exists when every side is less than the sum of the other two.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.