I am confused about the scope of the variable in python. Here is a toy example of what I am trying to do:
a = True
enumerated_set = enumerate(['tic','tac','toe'])
for i,j in enumerated_set:
if a == True:
print j
The result I get is:
tic
tac
toe
now,
print a
returns
`True`
and if I ran again
for i,j in enumerated_set:
if a == True:
print j
I get no output.
I am confused... Since globally a = True, why during the second loop the print was not executed.
I appreciate your help.
Edit: another example where I am confused
y = 'I like this weather'.split()
for item in y:
for i,j in enumerated_set:
if a == True:
print j
also produces no output....
enumerateevery time you want to use it.