KnowledgeBoat Logo

Computer Science

Which of the following command is used to open a file "c:\pat.txt" for writing in binary format only ?

  1. fout = open("c:\pat.txt", "w")
  2. fout = open("c:\\pat.txt", "wb")
  3. fout = open("c:\pat.txt", "w+")
  4. fout = open("c:\\pat.txt", "wb+")

Python File Handling

1 Like

Answer

fout = open("c:\\pat.txt", "wb")

Reason — The syntax to open a file for writing in binary format is f = open("c:\\temp\\data.txt", "wb"). Hence according to this syntax fout = open("c:\\pat.txt", "wb") format is correct.

Answered By

1 Like


Related Questions