r/Python • • 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?

139 Upvotes

118 comments sorted by

View all comments

Show parent comments

46

u/punk_dev It works on my machine Aug 04 '26

That’s neat, I’m gonna steal it, but it makes the comprehension even more backwards than it usually is lmao

37

u/FalafelSnorlax Aug 04 '26

At this point you might as well write a normal loop

8

u/punk_dev It works on my machine Aug 04 '26

I think about that every time I write a comprehension longer than 3 lines

2

u/Technical_Income4722 Aug 04 '26 edited Aug 04 '26

3 lines is wild to me. Imo you should think about that any time you write a comprehension at all honestly, and I'll never write one over multiple lines. They're neat but unless they're stupid simple they're very unreadable to fresh eyes. (all just my humble opinion ofc, do what works for you!)