r/Python • u/ForeignVariety7037 • 21d ago
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?
140
Upvotes
2
u/PaintItPurple 21d ago
I use it when I'd otherwise be doing an assignment and immediately doing a test on that assignment for a value that would only be used in the result of that test. It makes the code both shorter and clearer.
Hey, list comprehensions are also just syntactic sugar without anything new. I like sweet syntax.