what does := means simply?

Marko Rauhamaa marko at pacujo.net
Thu May 17 09:39:46 EDT 2018


Antoon Pardon <antoon.pardon at vub.be>:

> On 17-05-18 03:44, Chris Angelico wrote:
> 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

I know you must be joking but...

   while condition(a := prepare_a(), b := prepare_b()):
       Do other stuff.


Marko



More information about the Python-list mailing list