-1

I am a beginner in Python. Please see the below code:

for line in range(8):
    fact = 1
print(fact)

I received output as 1

My query is since fact variable is withing the scope of for loop, how does Python access the variable outside it's scope. Thank in advance.

METALHEAD
  • 2,384
  • 3
  • 18
  • 30

1 Answers1

1

Python has function-level scoping, not block-level. With a few exceptions, local variables are local to the whole of the enclosing function.

user200783
  • 13,080
  • 11
  • 62
  • 123