I am new to python and suddenly was surprised seeing that a variable is still visible outside the block in which it's declared and assigned. The code is below:
with open('data.txt', 'r') as file:
text = file.readlines()
# and when do I close the file?
for i in range(len(text)): # still can access the text even after the block.
print(text[i])
How is this possible for the variable to be seen from outside the block? Thanks in advance.