I have the following code:
a = ['bobby', 'freddy', 'jason']
b = ['pep', 'lin', 'cat']
for a in b:
for b in a:
when the for loop is created, does it store a copy of the iterator and then loop through that even if the original variable now "points" to a different value?
Yes! You identified it correctly. Typically, when such looping constructs occur, the interpreter calls
iter(object) and uses the returned iterator object for iteration. It does not matter if the original variable name is bound to some other object post this step.