Walrus Operator Motivation
01:15 The distinction between assignment statements and assignment expressions in Python is useful in order to avoid these kinds of hard to find bugs. PEP 572 argued that Python is better suited to having different syntax for assignment statements and expressions, instead of turning the existing assignment statements into expressions.
One design principle underpinning the walrus operator is that there are no identical code contexts where both an assignment statement using the equals operator (
=) and an assignment expression using the colon equals operator (
:=) would be valid. For example, you can’t do a plain assignment with the walrus operator.
Become a Member to join the conversation.