Variables within for loop

the variables created within for loop seems to still affect outside of the loop. Then can you say that those variables are global?

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Could you provide an example of what you mean, please?

for i in range(10):
        s = 11
        print(s)

print('one more' + s) 

at the end ‘one more 11’ is printed. isn’t it?

In Python, variable generally follow function scope-so if they are declared in the same function-i.e not a different function. Therefore this works:

for i in range(1):
  a=i
print(a)

but this does not:

def a_fun():
  for i in range(1):
     a = i
print(a)

I hope this helps!