create a text file in python and write line by line in python code example
Example 1: python writeline file
f = open("test.txt", "w")
f.writelines(["Hello", "World"])
f.close
Example 2: python write text file on the next line
file = open("sample.txt", "w")
file.write("Hello\n")
file.write("World\n")
file.close()