sInfoEra
Home
MCQs
Python — Quiz
File Handling in Python section 1
75 questions · Test your knowledge
Home
/
MCQs
/
File Handling in Python section 1
1
Which statement will read 5 characters from a file(file object ‘f’)?
A
f.read()
B
f.read(5)
C
f.reads(5)
D
None of the above
2
Which function open file in python?
A
open( )
B
new( )
C
Open( )
D
None of the above
3
Which mode create new file if the file does not exist?
A
write mode
B
append mode
C
Both of the above
D
None of the above
4
Which statement will return one line from a file (file object is ‘f’)?
A
f.readline( )
B
f.readlines( )
C
f.read( )
D
f.line( )
5
readlines() method return _________
A
String
B
List
C
Dictionary
D
Tuple
6
EOF stands for ___________
A
End of File
B
End off File
C
End on File
D
End or Fil
7
Which function is used to read data from Text File?
A
a. read( )
B
writelines( )
C
pickle( )
D
dump( )
8
Which of the following will read entire content of file(file object ‘f’)?
A
f.reads( )
B
f.read( )
C
f.read(all)
D
f.read( * )
9
Which symbol is used for append mode?
A
ap
B
a
C
w
D
app
10
Which of the following options can be used to read the first line of a text file data.txt?
A
f = open(‘data.txt’); f.read()
B
f = open(‘data.txt’,’r’); f.read(n)
C
myfile = open(‘data.txt’); f.readline()
D
f = open(‘data.txt’); f.readlines()
11
File in python is treated as sequence of ________________
A
Bytes
B
Bites
C
bits
D
None of the above
12
Which function is used to write data in binary mode?
A
write
B
writelines
C
pickle
D
dump
13
Which function is used to force transfer of data from buffer to file?
A
flush( )
B
save( )
C
move( )
D
None of the above
14
Let 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?
A
f.read( )
B
f.read(all)
C
f.readline( )
D
f.readlines( )
15
__________________ module is used for serializing and de-serializing any Python object structure.
A
pickle
B
unpickle
C
pandas
D
math
16
Which of the following error is returned when we try to open a file in write mode which does not exist?
A
FileNotFoundError
B
FileFoundError
C
FileNotExistError
D
None of the above
17
_____________ function returns the strings
A
read( )
B
readline( )
C
Both of the above
D
None of the above
18
The syntax of seek() is: file_object.seek(offset [, reference_point]) What is reference_point indicate?
A
reference_point indicates the starting position of the file object
B
reference_point indicates the ending position of the file object
C
reference_point indicates the current position of the file object
D
None of the above
19
Identify the invalid mode from the following.
A
a
B
. r+
C
ar+
D
w
20
Which of the following is an invalid mode of file opening?
A
read only mode
B
write only mode
C
read and write mode
D
write and append mode
21
readlines( ) function returns all the words of the file in the form of List. (T/F)
A
True
B
False
C
yes
D
Error
22
What is ‘f’ in the following statement? f=open("Data.txt" , "r")
A
File Name
B
File Handle
C
Mode of file
D
File Handling
23
What is full form of CSV
A
Comma Separation Value
B
Comma Separated Value
C
Common Syntax Value
D
Comma Separated Variable
24
Which statement will open file “data.txt†in append mode?
A
f = open(“data.txt†, “aâ€)
B
f = Open(“data.txt†, “abâ€)
C
f = new(“data.txt†, “aâ€)
D
open(“data.txt†, “aâ€)
25
Fill in the blank import pickle f=open("data.dat",'rb') d=_____________________.load(f) f.close()
A
unpickle
B
pickling
C
pickle
D
pick
26
Which module to be imported to make the following line functional? sys.stdout.write("ABC")
A
system
B
sys
C
stdout
D
stdin
27
What error is returned by the following statement if the file does not exist? f=open("A.txt")
A
FileNotFoundError
B
NotFoundError
C
NotFoundError
D
FoundError
28
Which statement will return error? import pickle f=open("data.dat",'rb') d=pickle.load(f) f.end()
A
Statement 1
B
Statement 2
C
Statement 3
D
Statement 4
29
Which of the following function takes two arguments?
A
load( )
B
dump( )
C
Both of the above
D
None of the above
30
Almost all the files in our computer stored as _______ File
A
Text
B
Binary
C
CSV
D
None of the above
31
pdf and .doc are examples of __________ files.
A
Text
B
Binary
C
CSV
D
None of the above
32
The syntax of seek() is:file_object.seek(offset [, reference_point]) What all values can be given as a reference point?
A
1
B
2
C
0
D
All of the above
33
Fill 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
A
csv
B
unpickle
C
pickle
D
load
34
Refer to the above code and choose the option for statement2.
A
w
B
w+
C
wb
D
write
35
Refer to the above code (Q 38)and choose the option for statement 3
A
unpickle
B
write
C
pickle
D
None of the above
36
Refer to the above code (Q 38)and choose the option for statement 4.
A
f
B
rec
C
file
D
stud
37
The syntax of seek() is:file_object.seek(offset [, reference_point] What is the default value of reference_point
A
0
B
1
C
2
D
3
38
_______ function returns the current position of file pointer. a.
A
get( )
B
tell( )
C
cur( )
D
seek( )
39
f.seek(10,0) will move 10 bytes forward from beginning of file.
A
True
B
False
C
yes
D
Error
40
Which statement will move file pointer 10 bytes backward from current position.
A
Which statement will move file pointer 10 bytes backward from current position. a. f.seek(-10, 0)
B
f.seek(10, 0)
C
f.seek(-10, 1)
D
None of the above
41
When we open file in append mode the file pointer is at the _________ of the file.
A
end
B
beginning
C
anywhere in between the file
D
second line of the file
42
When we open file in write mode the file pointer is at the _______ of the file.
A
end
B
beginning
C
anywhere in between the file
D
second line of the file
43
Write 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
A
Hello
B
Hell
C
ello
D
None of the above
44
Refer to the above code (Q 47) : Write the output of Second Print Statement
A
om
B
me
C
co
D
None of the above
45
Refer to the above code (Q 47) : Write the output of Third Print Statement
A
e to m
B
e to my
C
to my
D
None of the above
46
Refer to the above code (Q 47) : Write the output of Fourth Print Statement
A
17
B
16
C
19
D
18
47
A _____________ is a named location on a secondary storage media where data are permanently stored for later access
A
file
B
variable
C
comment
D
token
48
A _____ file consists of human readable characters.
A
Binary
B
Text
C
Both of the above
D
None of the above
49
Which of the following file require specific programs to access its contents?
A
Binary
B
Text
C
CSV
D
None of the above
50
Which of the following file can be opened in any text editor?
A
Binary
B
Text
C
Both of the above
D
None of the above
51
Each line of a text file is terminated by a special character, called the ____
A
End of File
B
End of Line
C
End of Statement
D
End of program
52
Default EOL character in text file is _____
A
B
N
C
D
l
53
Which of the following file can be created in python?
A
Text File
B
Binary File
C
CSV File
D
All the above
54
In which of the following data store permanently?
A
File
B
Variable
C
Both of the above
D
None of the above
55
open( ) function takes ____ as parameter.
A
File name
B
Access mode
C
Both of the above
D
None of the above
56
Identify the correct statement to open a file:
A
f = open(“D:\myfolder\naman.txtâ€)
B
f = open(“D:myfolder aman.txtâ€)
C
f = open(“D:myfolder#naman.txtâ€)
D
f = Open(“D:myfolder aman.txtâ€)
57
Which of the following are the attributes of file handle?
A
closed
B
name
C
mode
D
All the above
58
Write the output of the following: >>> f = open("test.txt","w") >>> f.closed
A
True
B
False
C
yes
D
Error
59
Write the output of the following: >>> f = open("test.txt","w") >>> f.mode
A
‘w’
B
‘r’
C
‘a’
D
w+’
60
Write the output of the following: >>> f = open("test.txt","w") >>> f.name
A
‘test’
B
‘test.txt’
C
test.dat’
D
file does not exist
61
Write the output of the following: >>> f = open("test.txt","w") >>> f.close() >>> f.closed
A
True
B
False
C
yes
D
No
62
Which of the following attribute of file handle returns Boolean value?
A
name
B
closed
C
mode
D
None of the above
63
Ravi opened a file in python using open( ) function but forgot to specify the mode. In which mode the file will open?
A
write
B
append
C
read
D
read and write both
64
Which of the following is invalid mode of opening file?
A
r
B
rb
C
+r
D
None of the above
65
Which of the following mode will create a new file, if the file does not exist?
A
‘a’
B
‘a+
C
‘+a’
D
All the above
66
Which of the following mode will open the file in binary and read-only mode.
A
‘r’
B
‘rb’
C
‘r+’
D
‘rb+’
67
Which of the following mode will opens the file in read, write and binary mode?
A
‘wb+
B
‘+wb’
C
Both of the above
D
None of the above
68
In the given statement, the file myfile.txt will open in _______________ mode. myObject=open(“myfile.txtâ€, “a+â€)
A
append and read
B
append and write
C
append and read and binary
D
All the above
69
Ravi opened the file myfile.txt in append mode. In this file the file object/file handle will be at the ___
A
beginning of the file
B
end of the file
C
second line of the file
D
the end of the first line
70
Ravi opened the file myfile.txt in write mode. In this file the file object/file handle will be at the __
A
beginning of the file
B
end of the file
C
second line of the file
D
the end of the first line
71
Ravi 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.
A
read mode
B
write mode
C
append mode
D
binary and read mode
72
Ram 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.
A
read mode
B
write mode
C
append mode
D
binary and read mode
73
Which of the following function is used to close the file?
A
close( )
B
end( )
C
quit( )
D
exit( )
74
open( ) function returns a file object called _____
A
object handle
B
file handle
C
read handle
D
write handle
75
Which of the following is the valid way to open the file?
A
with open (file_name, access_mode) as fo:
B
fo = open (file_name, access_mode)
C
Both of the above
D
None of the above
Submit Quiz
Back to All Quizzes