if x := 3:
print("x is now: ", x)
print("x isn't scoped to the if:",x)The walrus is for giving names to values you were computing anyway. Instead of a storage bin and the value you want to store there, the walrus involves a value and the name you want to refer to it by. Conceptually, the value is where you begin.
EDIT: Based the examples given, the Python := operator doesn't appear to behave as a let binding. The scoping suggests it is another form of assignment.
while (item := stack.pop()) is not None:
# ...
is a lot harder to get wrong than item = stack.pop()
while item is not None:
# ...
item = stack.pop()
Really wish it was scoped though...Edit: Just realised you were asking for an if-statement... but I think this is still a valid point.
Indeed, there's no intuitive of "the box that is referred to by the name on the left shall now contain the value that is the result of the computation on the right" since serious humans have had no need to express the concept.
Most people who code in Python have no idea what they're doing. It's all magical incantations that they fiddle with until it gives the output they want. That's why python prohibits
if x = some_computation()
since if it permitted it, everyone would be all wtf. But the number of people who can gather that "sequence of symbols taken as a unit" has some arbitrary new meaning almost certainly significantly exceeds the number of people who can gather that "symbol traditionally used for signifying equality" has some arbitrary new meaning.And, at the very least, if you see some incredible incomprehensible sequence of symbols you can ask what they mean. It is, however, necessary that you have not unknowingly misunderstood what the symbols mean before you can seek clarification, since no-one ever asks for clarification for something they fully but incorrectly understand.