w3resource logo

:

Python Exercises

Python File I/O: Assess if a file is closed or not

Python File I/O: Exercise-16 with Solution

Write a Python program to assess if a file is closed or not.

Sample Solution:-

Python Code:

 f = open('abc.txt','r')
print(f.closed)
f.close()
print(f.closed)

Sample Output:

False                                                                                                         
True

Python Code Editor:

Improve this sample solution and post your code through Disqus