syntax difference

Bart bc at freeuk.com
Tue Jun 19 06:52:22 EDT 2018


On 19/06/2018 11:33, Steven D'Aprano wrote:
> On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote:
> 
>> * Swap(x,y) (evaluate each once unlike a,y=y,x)
> 
> Sigh. Really? You think x,y = y,x evaluates x and y twice?

Yes. Try:

count=0

def fn():
	global count
	count=count+1
	return 1

a=[10,20,30,40]
b=[1,2,3,4]

a[1],b[fn()] = b[fn()],a[1]

print (a)
print (b)
print ("Count",count)

b[fn()] is evaluated twice.


(May reply to other points of yours and Chris' in a few days.)

-- 
bart



More information about the Python-list mailing list