Home >>Python File Methods >Python File close() Method

Python File close() Method

Python File close() Method

Python file close() method is used to close an open file. Files should always be closed because changes made to a file may not show until you close the file.

Syntax:
file.close()
Here is an example of Python close() method:

f = open("test.txt", "r")
print(f.read())
f.close()

Output:
Hello! Welcome to test.txt
This file is for testing purposes.
Good Luck!

No Sidebar ads