Articles → Python → Write In Text File In PythonWrite In Text File In PythonIn this article, we will write in text file using Python.Example Here is an example: -myfile = open("test.txt","w") myfile.write("This is the test message") myfile.close()This code will add text to the 'test.txt' file. You can verify the second parameter of the 'open' function, where 'w' denotes the write mode, which will overwrite any existing data. If you wish to append data instead, you can specify 'a'.Posted By - Karan Gupta Posted On - Monday, March 4, 2019 Query/Feedback Your Email Id Subject Query/Feedback Characters remaining 250
myfile = open("test.txt","w") myfile.write("This is the test message") myfile.close()
Query/Feedback