In messing around with some old code I posted awhile back, I came across something odd. Rather than using i += prim
in my code, I've got this ugly i = i + prim
. Not a big deal, I'll just changed it while changing other things. But what's this? My code is broken!
def gen_all_pyth_trips(limit):
for prim in gen_prim_pyth_trips(limit):
i = prim
for _ in range(limit//prim[2]):
yield i
# i = i + prim
i += prim
So I'm pretty sure this has something to do with the fact that the first one is creating a new object and telling i
to reference it while the second one is changing the object that i
is referencing (thus changing prim
and all the yielded arrays) but the reasons aren't all that obvious (to me at least).
If someone could point me to some documentation and/or explain what exactly is going on here, I'd be much obliged.