write()

say it: “RYTE” /ˈraɪt/

Puts text into an open file.

What does write() do?

write() puts text into an open file. It doesn't add a new line for you, so include \n where you want one.

with open("todo.txt", "w") as file:
    file.write("Buy milk\n")
    file.write("Call mom\n")

Level: Apprentice · More Python terms at this level

Updated