what does := means simply?
Antoon Pardon
antoon.pardon at vub.be
Thu May 17 08:56:32 EDT 2018
On 17-05-18 03:44, Chris Angelico wrote:
> On Thu, May 17, 2018 at 11:33 AM, Abdur-Rahmaan Janhangeer
> <arj.python at gmail.com> wrote:
>> what does := proposes to do?
>>
>> pep572
>>
> If you read the PEP, you'll find an answer to your question.
>
> https://www.python.org/dev/peps/pep-0572/
>
> ChrisA
Just wondering, but in discussing this PEP has one considered
making the ';' into an expression too, with the value being
the value of the last expression?
I just ask because sometimes I have a loop that now often is written
as follows:
while True:
a = prepare_a()
b = prepare_b()
if not condition(a, b):
break
Do other stuff
Now with the := assignment it seems I will be able to write it like this:
while [a := prepare_a(), b := prepare_b(), condition(a, b)][-1]:
Do other stuff.
But IMO it would be nicer if it could be written as:
while a := prepare_a(); b := prepare_b(); condition(a, b):
Do other stuff
--
Antoon Pardon
More information about the Python-list
mailing list