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

Python File writelines() Method

Python File writelines() Method

Python File writelines() Method is an inbuilt method in python, it is used to writes a sequence of strings to the file where, you can inserted text depends on the file mode stream position and there is no return value.

Syntax:
file.writelines(list)

Parameter Values

Parameter Description
list Used to inserted a list of a text object.
Here is an example of Python File writelines() Method:

e = open("file3.txt", "a")
e.writelines(["Hello!", "Welcome to my World."])
e.close()
e = open("file3.txt", "r")
print(e.read())

Output:
Hello! Welcome to file3.txt
Good Luck!Hello! Welcome to my World.
Example 2:

j = open("file4.txt", "a")
j.writelines(["Hello!", "Welcome to phptpoint."])
j.close()
j = open("file4.txt", "r")
print(j.read())

Output:
Hello! Welcome to file4.txt
Good Luck!Hello! Welcome to phptpoint.