Which function is used to write in a file without over writing the previous content?
Which function is used to write in a file without over writing the previous content?
Solution
✅ Correct Option: 1
Append adds new content at the end of a file and keeps what is already there, whereas write mode ("w") erases the old content first. In Python this is done by opening the file in append mode, , and then writing to it.
Option 3: add() is a set method in Python, not a file operation.
Options 2 and 4: read() only reads data, and close() only closes the file. Neither writes anything.
Related questions:
2025: 15 May Shift 2
2025: 30 May Shift 2
2026: 19 May Shift 1