what does := means simply?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 17 13:29:56 EDT 2018


On Thu, 17 May 2018 17:50:22 +0300, Marko Rauhamaa wrote:

> bartc <bc at freeuk.com>:
>> Anyway, try this:
>>
>>     def showarg(x): print(x)
>>
>>     def dummy(*args,**kwargs): pass
>>
>>     dummy(a=showarg(1),*[showarg(2),showarg(3)])
>>
>> This displays 2,3,1 showing that evaluation is not left to right.
> 
> Nice one!

I'm fairly sure that both you and Bart know full well I was talking about 
positional arguments. My example used only positional arguments, and my 
reply to Serhiy explicitly referenced positional arguments.

But don't bother responding to what I *actually* said, it's much more fun 
to attack a strawman, right?

And besides, Bart's "showarg" function is a waste of space: it could be 
simply replaced by print.

py> dummy(a=print(1), *[print(2), print(3)])
2
3
1

You want some more examples of non-left to right evaluation order?

Comprehensions.

Ternary if.

Are there any others? Could be. So what? The existence of odd corner 
cases in the language doesn't invalidate my example that doesn't go 
anywhere near those odd corners.


-- 
Steve




More information about the Python-list mailing list