Chapters
Python114 chapters

ReferenceFile methods

file.close()

Closes the file and flushes anything not yet written.

Signature

f.close()

Returns

None.

Example

Python
f = open("notes.txt", "w", encoding="utf-8")
f.write("one")
print(f.closed)
f.close()
print(f.closed)

Output

False
True

See also