Account
Categories

Writing Files


Definition:

In Python, the write() method is used to put or save text/data from the program into a file.

Syntax:

file_handle = open("file_name", "w")
file_handle.write("Your text here")
file_handle.close()

Example:

f = open("file1.txt", "w")
f.write("Welcome to www.edutation.com")
f.close()

Output: