you can either manually manage the memory with `del cnt` or let the built in memory management .. manage the memory.
On Wed, Aug 7, 2013 at 10:54 PM, Jim Mooney <[email protected]>wrote: > This bugs me for some reason. The final variable is saved in a for > loop but not in a list comprehension. It just seems to me they should > both be destroyed to avoid confusion. > > lst = [] > for cnt in range(5): > lst.append(cnt) > cnt > 4 > > lst = [cnt2 for cnt2 in range(5)] > cnt2 > builtins.NameError: name 'cnt2' is not defined > > Is there a form of for loop that would destroy the loop variable? I > could always do del cnt right after the for, but that seems > artificial. > > -- > Jim > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
