Background ("PEP 572 and decision-making in Python"):
replies(2):
Thanks Guido for fantastic language. I wouldn't find love for programming if it wasn't for you.
I feel like a lot of the resistance is from people who think this is somehow bad style, because it's associated with a source of bugs in other languages. The same kind of people will argue endlessly against having 'goto' in a language, even when it can clearly make for cleaner code (eat it, Dijkstra!) in some cases.
x = stuff
while x:
x = stuff
Another motivating code pattern is the "loop and a half".
It was once common for processing a file by line, but that
has been solved by making file objects iterable; however
other non-iterable interfaces still suffer from patterns
like:
line = f.readline()
while line:
... # process line
line = f.readline()
or like this:
while True:
line = f.readline()
if not line:
break
... # process line
Either of those could be replaced with a much more clear
and concise version using an assignment expression:
while line := f.readline():
... # process line
[0]: https://lwn.net/Articles/757713/