Knowledge organisersFile Handling Techniques
Append or overwrite content.
Use .write() to save text to a file. Remember to add \n for new lines — write() does not add them automatically. Use "w" to start fresh or "a" to add to existing content.
.write(text) saves text to the file\n explicitly"w" mode creates/overwrites; "a" mode appendsstr() firstscores = [85, 92, 78]
with open("scores.txt", "w") as f:
for s in scores:
f.write(str(s) + "\n")