Which of the following is the correct method to write into a text file.
Which of the following is the correct method to write into a text file.
Solution
✅ Correct Option: 1
The write() method of a file object writes a string to a text file opened in a write or append mode such as "w" or "a". For example, fileobj.write("Hello") writes the text "Hello" into the file.
Option 2: seek() only moves the file pointer to a given position, and it writes nothing.
Option 3: read() reads data from a file, which is the opposite of writing.
Option 4: peep() is not a file method in Python.
writelines() is also used for writing, and it writes a list of strings to the file.
Related questions:
2025: 13 May Shift 2
2025: 14 May Shift 1
2026: 26 May Shift 1