Computer Science

Which of the following command is used to open a file "c:\pat.txt" in read-mode only ?

  1. fin = open("c:\pat.txt", "r")
  2. fin = open("c:\\pat.txt", "r")
  3. fin = open(file = "c:\pat.txt", "r+")
  4. fin = open(file = "c:\\pat.txt", "r+")

Python File Handling

1 Like

Answer

fin = open("c:\\pat.txt", "r")

Reason — The syntax to open a file in read-mode only is f = open("c:\\temp\\data.txt", "r"). Hence according to this syntax fin = open("c:\\pat.txt", "r") format is correct.

Answered By

3 Likes


Related Questions