Articles → Python → Write In Text File In PythonWrite In Text File In PythonIn this article, we will write in text fileExample Here is an examplemyfile = open("test.txt","w") myfile.write("This is the test message") myfile.close()This will write text in test.txt. If you can check the second parameter for open. Here ‘w’ specifies the write mode. It overrides the existing data. In case you want to append the data, you can mention ‘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