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

Python File write() Method

Python File write() Method

Python File write() Method in python file inserted a specified text depends on the file mode and helps to write a specified text to the file.

Syntax:
file.write(byte)

Parameter Values

Parameter Description
byte Used for inserted a text object
Here is an example of Python File write() Method:

e= open("file1.txt", "a")
e.write("how are you!")
e.close()
e= open("file1.txt", "r")
print(e.read())

Output:
Hello! Welcome to file1.txt
Good Luck! how are you!
Example 2:

z= open("file2.txt", "a")
z.write("Hello!")
z.close()
z= open("file2.txt", "r")
print(z.read())

Output:
Hello! Welcome to file1.txt
Good Luck! Hello!

No Sidebar ads