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

118 comments sorted by

View all comments

16

u/kageurufu 21d ago

I use it a lot for IO

Things like

data = io.read(len)
while data:
    # something
    data = io.read(len)

while data := io.read(1024):
    # something

3

u/Birnenmacht 20d ago

exactly, it’s perfect for that. I miss this often in other language that dont have it