|
|
|
|
|
by frogcoder
1479 days ago
|
|
Funny, I think the walrus operator makes code cleaner and easier to understand. Many of my code were like this: foo = one_or_none()
if foo:
do_stuff(foo)
Now I have the following: if foo := one_or_none():
do_stuff(foo)
This kind of code happens quite frequently, looks nicer with walrus operator to me. |
|
In both cases, "foo" continues to exist after the "if" even though the second example makes it look like "foo" is scoped to the "if".
So to my eye, the following would look super weird (assume do_more_stuff can take None):
whereas the following would look fine: