Example:
x=y=z=True
I'm wondering if is bad performance-wise due memory or smth since bool for example is immutable.
Example:
x=y=z=True
I'm wondering if is bad performance-wise due memory or smth since bool for example is immutable.
With single names, it has exactly the same semantics as
x=True
y=x
z=x
but (depending on the “optimization” in the compiler) might be more efficient because it doesn’t (naïvely) involve reloading the value stored into x
.
With complicated names, more complicated behaviors can occur:
a[i]=i=j
This updates a[i]
(with the old i
) and then sets i
to the same value. Whether this is more or less clear than
a[i]=j
i=j
depends both on the nature of the algorithm (is it conceptually significant that i
follows the indices as they are assigned in some sort of permutation?) and on whether j
is just a variable or is actually some complicated expression that does not bear repeating. (One could of course write
new_i=j
a[i]=new_i
i=new_i
but remember that additional variable names also cost in terms of readability—is new_i
used later?)