text = "Hello world" filename = "file.txt" with open(filename, "w") as file: file.write(text)