4 ms·
I write a good deal of python and I can't think of a line of code that I would use it for besides the while loop on a non-iterable data source, which is such a
by adjkant 7y ago
I write a good deal of python and I can't think of a line of code that I would use it for besides the while loop on a non-iterable data source, which is such a once in a blue moon case. As mentioned by others, the operator invites more ways to do the same thing, which is not what Python has been viewed as being about.
- orangecat 7y agoVictor Stinner made a demonstration pull request using the walrus operator in the standard library where it makes sense. On balance it removes several hundred lines and often makes the code much clearer, e.g. https://github.com/python/cpython/pull/8122/files#diff-78e8ea3354eac632b8978306b0275826L1425 https://github.com/python/cpython/pull/8122/files#diff-78e8e...
- mixmastamyk 7y agoThe argument was about mostly about the syntax. In the link above, the "as" keyword would work with (very close to) all of those lines and arguably more readable.
- drexlspivey 7y agoI do this all the time: x = function_that_might_return_none() if x: do_stuff