Decode School


Free Certification Courses from

File Write in python

Python Program to Earse the content of file sample.txt and write something new.

Program or Solution

					    
							
file=open("sample1.txt",'w')
content=input("Enter a String:")
file.write(content)
file.close()

					    
					

Program Explanation

open the file in write mode write the content into the file using write() method close() the file.