Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question