#sample text text = "Hi this is a sample text." #write the text string into a text file with("filename.txt",'w') as open_file: open_file.write(text)