Walrus Operator

say it: “WAWL-rus OP-uh-ray-ter” /ˈwɔlrəs ˈɑpəˌreɪtɚ/

The := operator: saves a value and uses it in the same line.

What is the walrus operator?

The walrus operator (:=) saves a value into a variable and uses it in the same line, so you don't have to work it out twice.

while (answer := input("Command (q to quit): ")) != "q":
    print("You typed", answer)

Level: Journeyman · More Python terms at this level

Updated