To write into a file, we use mode "w" (overwrite) or "a" (append).
python
# "w" will overwrite the file
with open("log.txt", "w") as f:
f.write("Log started.\n")
# "a" will append to the end
with open("log.txt", "a") as f:
f.write("New entry added.")
# Read the final file to verify
with open("log.txt", "r") as f:
print(f.read())You should see
Log started. New entry added.