I have searched the SO before I post this question here and hopefully this is not a duplicated one.
def print_me():
a_list = range(1, 10)
for idx, aa in enumerate(a_list):
pass
print(idx)
if __name__ == '__main__' : print_me()
Output is as follows:
8
I came from C++ world and could not figure out why idx
is still in the scope when
the code is out side of for loop?
Thank you