Continuous assignment to multiple variables in python

See a piece of code as follows

self.batch_size = batch_size = 128

It was surprising at first glance, but it makes perfect sense when you think about it.

In python, it may be necessary to declare multiple variables at the same time, and assign the same initial value to multiple variables, which can be assigned in the following ways

a=b=c=1

But it should also be noted here that if the assignment is a list or a dictionary, such as

a=b=c=[1,2,3]

Then a, b, and c are all pointers to lists, rather than copying, changing one will change the others.
For example, let a[1] = 4, then b=[1,4,3]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325839979&siteId=291194637