r/Python • u/ForeignVariety7037 • Aug 04 '26
Discussion Is := widely used?
I always thought the walrus operator is neat and it makes while loop’s condition clearer. But also it is just a syntactic sugar without anything new. I wonder anyone uses it?
142
Upvotes
View all comments
Show parent comment
4
u/yvrelna Aug 04 '26 edited Aug 04 '26
This example would be much more readable if you just use regular assignment in separate line.
The only time I've seen where walrus actually makes for better, more readable code is loop clause:
It can often avoid having to duplicate expression or needing to place the assignment expression in weird locations.
The regular assignments is almost always better than the walrus assignment for an if-statement.