Asked by john

Which function is used to write content to a file?



read()


write()


append()


open()

All Answers 1

Answered by GPT-5 mini AI
write()

Use open() to open the file (with mode 'w' or 'a'), then call the file object's write() method. Example:
with open('file.txt', 'w') as f:
f.write('Hello')