- Which function is used to open a file in Python?
View Answer
Correct answer: B — open()
- What will be printed?
1 f = open("eduinq.txt","w") 2 print(f.mode) View Answer
Correct answer: A — w
- Which of the following is used to read file contents?
View Answer
Correct answer: A — f.read()
- What is the output of print(open("eduinq.txt").closed)?
View Answer
Correct answer: B — False
- Which of the following is used to close a file?
View Answer
Correct answer: B — f.close()
- What will be printed?
1 f = open("eduinq.txt","w") 2 f.write("Eduinq") 3 f.close() 4 f = open("eduinq.txt","r") 5 print(f.read()) View Answer
Correct answer: A — Eduinq
- Which of the following is used to read one line at a time?
View Answer
Correct answer: A — f.readline()
- What is the output of print(open("eduinq.txt","r").mode)?
View Answer
Correct answer: A — r
- Which of the following is used to append data to file?
View Answer
Correct answer: A — "a" mode
- What will be printed?
1 f = open("eduinq.txt","a") 2 f.write("Python") 3 f.close() 4 f = open("eduinq.txt","r") 5 print(f.read()) View Answer
Correct answer: A — EduinqPython
- Which of the following is used to read all lines into list?
View Answer
Correct answer: A — f.readlines()
- What is the output of print(open("eduinq.txt","rb").mode)?
View Answer
Correct answer: A — rb
- Which of the following is used to write binary data?
View Answer
Correct answer: A — "wb" mode
- What will be printed?
1 f = open("eduinq.txt","w") 2 f.write("Eduinq\nPython") 3 f.close() 4 f = open("eduinq.txt","r") 5 print(f.readlines()) View Answer
Correct answer: A — ['Eduinq\n','Python']
- Which of the following is used to check file name?
View Answer
Correct answer: A — f.name
- What is the output of print(open("eduinq.txt","r").read(3))?
View Answer
Correct answer: A — Edu
- Which of the following is used to move file pointer?
View Answer
Correct answer: A — f.seek()
- What will be printed?
1 f = open("eduinq.txt","w") 2 f.write("Eduinq") 3 f.seek(0) 4 f.write("Py") 5 f.close() 6 f = open("eduinq.txt","r") 7 print(f.read()) View Answer
Correct answer: A — Pyinq
- Which of the following is used to get current file pointer position?
View Answer
Correct answer: A — f.tell()
- What is the output of print(open("eduinq.txt","r").readline()) if file contains "Eduinq"?
View Answer
Correct answer: A — Eduinq
- Which of the following is used to open file in exclusive creation mode?
View Answer
Correct answer: A — "x"
- What will be printed?
1 f = open("eduinq.txt","x") 2 f.write("Eduinq") 3 f.close() 4 f = open("eduinq.txt","r") 5 print(f.read()) View Answer
Correct answer: A — Eduinq
- Which of the following is used to open file in read/write mode?
View Answer
Correct answer: D — All of the above
- What is the output of print(open("eduinq.txt","r+").mode)?
View Answer
Correct answer: A — r+
- Which of the following is used to open file in text mode?
View Answer
Correct answer: A — "t"
- What will be printed?
1 f = open("eduinq.txt","wt") 2 f.write("Eduinq") 3 f.close() 4 f = open("eduinq.txt","rt") 5 print(f.read()) View Answer
Correct answer: A — Eduinq
- Which of the following is used to open file in binary mode?
View Answer
Correct answer: A — "b"
- What is the output of print(open("eduinq.txt","rb").read()) if file contains "Eduinq"?
View Answer
Correct answer: A — b'Eduinq'
- Which of the following is used to write multiple lines?
View Answer
Correct answer: A — f.writelines()
- What will be printed?
1 f = open("eduinq.txt","w") 2 f.writelines(["Eduinq\n","Python\n"]) 3 f.close() 4 f = open("eduinq.txt","r") 5 print(f.read()) View Answer
Correct answer: A — Eduinq\nPython\n
- Which of the following is used to automatically close file?
View Answer
Correct answer: A — with open() as f
- What is the output of print(f.closed) after using with open()?
View Answer
Correct answer: A — True
- Which of the following is used to check file existence?
View Answer
Correct answer: A — os.path.exists()
- What will be printed?
1 import os 2 print(os.path.exists("eduinq.txt")) View Answer
Correct answer: A — True or False
- Which of the following is used to delete file?
View Answer
Correct answer: A — os.remove()
- What is the output of print(os.remove("eduinq.txt"))?
View Answer
Correct answer: A — None
- Which of the following is used to rename file?
View Answer
Correct answer: A — os.rename()
- What will be printed?
1 import os 2 os.rename("eduinq.txt","python.txt") 3 print(os.path.exists("python.txt")) View Answer
Correct answer: A — True
- Which of the following is used to get file size?
View Answer
Correct answer: A — os.path.getsize()
- What is the output of print(os.path.getsize("eduinq.txt")) if file contains "Eduinq"?
View Answer
Correct answer: A — 6
- Which of the following is used to copy file?
View Answer
Correct answer: A — shutil.copy()
- What will be printed?
1 import shutil 2 shutil.copy("eduinq.txt","copy.txt") 3 print(open("copy.txt","r").read()) View Answer
Correct answer: A — Eduinq
- Which of the following is used to move file?
View Answer
Correct answer: A — shutil.move()
- What is the output of print(open("eduinq.txt","r").readline()) if file contains "Eduinq\nPython"?
View Answer
Correct answer: A — Eduinq
- Which of the following is used to truncate file?
View Answer
Correct answer: A — f.truncate()
- What will be printed?
1 f = open("eduinq.txt","w") 2 f.write("EduinqPython") 3 f.truncate(6) 4 f.close() 5 f = open("eduinq.txt","r") 6 print(f.read()) View Answer
Correct answer: A — Eduinq
- Which of the following is used to flush file buffer?
View Answer
Correct answer: A — f.flush()
- What is the output of print(open("eduinq.txt","r").read()) if file is empty?
View Answer
Correct answer: A — ""
- Which of the following is used to open file in append+read mode?
View Answer
Correct answer: A — "a+"
- What will be printed?
1 f = open("eduinq.txt","a+") 2 f.write("Eduinq") 3 f.seek(0) 4 print(f.read()) View Answer
Correct answer: A — Eduinq