Python - Context Managers
What will be the output of this code?
with open('sample.txt', 'w') as f:
f.write('Hi')
print(f.closed)with open('sample.txt', 'w') as f:
f.write('Hi')
print(f.closed)f exists outside the with block but the file is closed after the block.closed attributef.closed is True because the file is closed automatically.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions