Review each question and reveal answers to strengthen your understanding
1
Which statement will read 5 characters from a file(file object ‘f’)?
✅ Correct Answer: 2
2Which function open file in python?
✅ Correct Answer: 1
3Which mode create new file if the file does not exist?
✅ Correct Answer: 3
4Which statement will return one line from a file (file object is ‘f’)?
✅ Correct Answer: 1
5readlines() method return _________
✅ Correct Answer: 2
6EOF stands for ___________
✅ Correct Answer: 1
7Which function is used to read data from Text File?
✅ Correct Answer: 1
8Which of the following will read entire content of file(file object ‘f’)?
✅ Correct Answer: 2
9Which symbol is used for append mode?
✅ Correct Answer: 1
10Which of the following options can be used to read the first line of a text file data.txt?
✅ Correct Answer: 3
11File in python is treated as sequence of ________________
✅ Correct Answer: 1
12 Which function is used to write data in binary mode?
✅ Correct Answer: 4
13Which function is used to force transfer of data from buffer to file?
✅ Correct Answer: 1
14Let the file pointer is at the end of 3rd line in a text file named “data.txtâ€. Which of the following option can be used to read all the remaining lines?
✅ Correct Answer: 4
15__________________ module is used for serializing and de-serializing any Python object structure.
✅ Correct Answer: 1
16Which of the following error is returned when we try to open a file in write mode which does not exist?
✅ Correct Answer: 4
17_____________ function returns the strings
✅ Correct Answer: 3
18 The syntax of seek() is: file_object.seek(offset [, reference_point])
What is reference_point indicate?
✅ Correct Answer: 1
19Identify the invalid mode from the following.
✅ Correct Answer: 3
20 Which of the following is an invalid mode of file opening?
✅ Correct Answer: 4
21readlines( ) function returns all the words of the file in the form of List. (T/F)
✅ Correct Answer: 1
22What is ‘f’ in the following statement?
f=open("Data.txt" , "r")
✅ Correct Answer: 2
23What is full form of CSV
✅ Correct Answer: 2
24 Which statement will open file “data.txt†in append mode?
✅ Correct Answer: 1
25 Fill in the blank
import pickle
f=open("data.dat",'rb')
d=_____________________.load(f)
f.close()
✅ Correct Answer: 3
26Which module to be imported to make the following line functional?
sys.stdout.write("ABC")
✅ Correct Answer: 2
27What error is returned by the following statement if the file does not exist?
f=open("A.txt")
✅ Correct Answer: 1
28Which statement will return error?
import pickle
f=open("data.dat",'rb')
d=pickle.load(f)
f.end()
✅ Correct Answer: 4
29Which of the following function takes two arguments?
✅ Correct Answer: 2
30 Almost all the files in our computer stored as _______ File
✅ Correct Answer: 2
31pdf and .doc are examples of __________ files.
✅ Correct Answer: 2
32The syntax of seek() is:file_object.seek(offset [, reference_point]) What all values can be given as a reference point?
✅ Correct Answer: 4
33Fill in the blanks in the following code of writing data in binary files. Choose the answer for statement 1
import ___________ # Statement 1
rec = [ ]
while True:
rn = int(input("Enter"))
nm = input("Enter")
temp = [rn, nm]
rec.append(temp)
ch = input("Enter choice (Y/N)")
if ch.upper == "N":
break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4
✅ Correct Answer: 3
34Refer to the above code and choose the option for statement2.
✅ Correct Answer: 2
35Refer to the above code (Q 38)and choose the option for statement 3
✅ Correct Answer: 3
36Refer to the above code (Q 38)and choose the option for statement 4.
✅ Correct Answer: 1
37The syntax of seek() is:file_object.seek(offset [, reference_point] What is the default value of reference_point
✅ Correct Answer: 2
38_______ function returns the current position of file pointer.
a.
✅ Correct Answer: 2
39f.seek(10,0) will move 10 bytes forward from beginning of file.
✅ Correct Answer: 1
40Which statement will move file pointer 10 bytes backward from current position.
✅ Correct Answer: 3
41 When we open file in append mode the file pointer is at the _________ of the file.
✅ Correct Answer: 1
42When we open file in write mode the file pointer is at the _______ of the file.
✅ Correct Answer: 2
43Write the output of the First Print statements :
f=open("data.txt",'w')
f.write("Hello")
f.write("Welcome to my Blog")
f.close()
f=open("data.txt",'r')
d=f.read(5)
print(d) # First Print Statement
f.seek(10)
d=f.read(3)
print(d) # Second Print Statement
f.seek(13)
d=f.read(5)
print(d) # Third Print Statement
d=f.tell()
print(d) # Fourth Print Statement
✅ Correct Answer: 1
44Refer to the above code (Q 47) : Write the output of Second Print Statement
✅ Correct Answer: 2
45 Refer to the above code (Q 47) : Write the output of Third Print Statement
✅ Correct Answer: 3
46Refer to the above code (Q 47) : Write the output of Fourth Print Statement
✅ Correct Answer: 4
47A _____________ is a named location on a secondary storage media where data are permanently stored for later access
✅ Correct Answer: 1
48 A _____ file consists of human readable characters.
✅ Correct Answer: 2
49Which of the following file require specific programs to access its contents?
✅ Correct Answer: 1
50Which of the following file can be opened in any text editor?
✅ Correct Answer: 2
51Each line of a text file is terminated by a special character, called the ____
✅ Correct Answer: 2
52Default EOL character in text file is _____
✅ Correct Answer: 1
53Which of the following file can be created in python?
✅ Correct Answer: 4
54In which of the following data store permanently?
✅ Correct Answer: 1
55 open( ) function takes ____ as parameter.
✅ Correct Answer: 3
56Identify the correct statement to open a file:
✅ Correct Answer: 1
57Which of the following are the attributes of file handle?
✅ Correct Answer: 4
58Write the output of the following:
>>> f = open("test.txt","w")
>>> f.closed
✅ Correct Answer: 2
59Write the output of the following:
>>> f = open("test.txt","w")
>>> f.mode
✅ Correct Answer: 1
60Write the output of the following:
>>> f = open("test.txt","w")
>>> f.name
✅ Correct Answer: 2
61 Write the output of the following:
>>> f = open("test.txt","w")
>>> f.close()
>>> f.closed
✅ Correct Answer: 1
62Which of the following attribute of file handle returns Boolean value?
✅ Correct Answer: 2
63Ravi opened a file in python using open( ) function but forgot to specify the mode. In which mode the file will open?
✅ Correct Answer: 3
64Which of the following is invalid mode of opening file?
✅ Correct Answer: 4
65Which of the following mode will create a new file, if the file does not exist?
✅ Correct Answer: 3
66Which of the following mode will open the file in binary and read-only mode.
✅ Correct Answer: 2
67Which of the following mode will opens the file in read, write and binary mode?
✅ Correct Answer: 2
68In the given statement, the file myfile.txt will open in _______________ mode.
myObject=open(“myfile.txtâ€, “a+â€)
✅ Correct Answer: 1
69 Ravi opened the file myfile.txt in append mode. In this file the file object/file handle will be at the ___
✅ Correct Answer: 2
70Ravi opened the file myfile.txt in write mode. In this file the file object/file handle will be at the __
✅ Correct Answer: 1
71Ravi opened a file in a certain mode. After opening the file, he forgot the mode. One interesting fact about that mode is †If the file already exists, all the contents will be overwrittenâ€. Help him to identify the correct mode.
✅ Correct Answer: 2
72Ram opened a file in a certain mode. After opening the file, he forgot the mode. The interesting facts about that mode are †If the file doesn’t exist, then a new file will be created†and “After opening file in that mode the file handle will be at the end of the file†Help him to identify the correct mode.
✅ Correct Answer: 3
73Which of the following function is used to close the file?
✅ Correct Answer: 1
74open( ) function returns a file object called _____
✅ Correct Answer: 2
75Which of the following is the valid way to open the file?