I searched for SO before posting this question here and hopefully this is not duplicated.
def print_me(): a_list = range(1, 10) for idx, aa in enumerate(a_list): pass print(idx) if __name__ == '__main__' : print_me()
The output is as follows:
-
I came from the C ++ world and couldn't understand why idx is still in scope when the code is outside the for loop?
thanks
python
q0987
source share