-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,734
  • 3
  • 22
  • 37

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,722
  • 12
  • 69
  • 135