The close method
The close method closes a previously opened file to free up system resources. The method does not return anything. We do not specify anything in the method parameter.
Syntax
file.close()
Example
Let's open the file file.txt, read its contents, and then close it:
res = open('file.txt', 'r')
print(res.read())
res.close()
The result of the executed code:
text