CUET-UG SERIES Computer-science
File Handling In Python
19 previous year questions.
Volume: 19 Ques
Yield: Medium
High-Yield Trend
6
2025 4
2024 9
2023 Chapter Questions 19 MCQs
01
PYQ 2023
medium
computer-science ID: cuet-ug-
Match List I with List II
| LIST I | LIST II |
|---|---|
| A. write lines | III. Writing a sequence of string |
| B. pickle | I. Module for binary files |
| C. try-except | IV. Exception handling |
| D. rb | II. Opening and reading a binary file |
1
A-III, B-IV, C-II, D-I
2
A-IV, B-I, C-III, D-II
3
A-III, B-IV, C-I, D-II
4
A-III, B-I, C-IV, D-II
02
PYQ 2023
medium
computer-science ID: cuet-ug-
Which of the following represents the mode of both writing and reading in binary format in a file?
1
wb+
2
w
3
a+
4
w+
03
PYQ 2023
medium
computer-science ID: cuet-ug-
Which of the following is not a valid mode to open a file?
1
ab
2
rw
3
r+
4
w+
04
PYQ 2023
medium
computer-science ID: cuet-ug-
Which error is generated by pickle.load() function when you reach end-of-file while reading from the file?
1
EOL error
2
EOF error
3
File doesn't exist
4
No error is generated
05
PYQ 2023
medium
computer-science ID: cuet-ug-
Which of the file modes in the following is invalid for a text-file?
1
a
2
w
3
r
4
ab
06
PYQ 2023
medium
computer-science ID: cuet-ug-
Which offset of the seek() method in the following is not valid?
1
0 - is for the beginning of the file.
2
1 - the middle position of the file.
3
2 - for the end of the file.
4
1 - for the current position of file pointer.
07
PYQ 2023
medium
computer-science ID: cuet-ug-
seek(1) method in files used for:
1
Sets the file's current position at the offset
2
Sets the file's previous position at the offset
3
Sets the file's current position within the file
4
Tells you the file is opened or not
08
PYQ 2023
medium
computer-science ID: cuet-ug-
Which of the following statements are true with respect to append \textless a\textgreater\ mode?
A. The user can read the file in \textless a\textgreater\ mode.
B. If the file is opened in \textless a\textgreater\ mode and the file doesn’t exist, then it will create a new file.
C. The user can write at the end of existing file when file is opened in \textless a\textgreater\ mode.
D. \textless a\textgreater\ mode is the default mode.
E. If the file is opened in \textless a\textgreater\ mode, the file offset position returned in the End of the file.
Choose the correct answer from the options given below:
A. The user can read the file in \textless a\textgreater\ mode.
B. If the file is opened in \textless a\textgreater\ mode and the file doesn’t exist, then it will create a new file.
C. The user can write at the end of existing file when file is opened in \textless a\textgreater\ mode.
D. \textless a\textgreater\ mode is the default mode.
E. If the file is opened in \textless a\textgreater\ mode, the file offset position returned in the End of the file.
Choose the correct answer from the options given below:
1
A, B and C only
2
A, B, C and E only
3
A, B and D only
4
B, C and E only
09
PYQ 2023
medium
computer-science ID: cuet-ug-
Match List I with List II
Choose the correct answer from the options given below :
| List I | List II | ||
| A. | tell() | I. | This function used to position the file object at particular position in a file |
| B. | seek() | II. | This function returns an integer that specifies the current position of the object in the file |
| C. | dump() | III. | This function is used to convert Python objects for writing data in a binary file |
| D. | load() | IV. | This function is used to load data from a binary file |
1
A-I, B-II, C-III, D-IV
2
A-II, B-I, C-III, D-IV
3
A-III, B-IV, C-I, D-II
4
A-IV, B-III, C-I, D-II
10
PYQ 2024
medium
computer-science ID: cuet-ug-
In Python, ________ module needs to be imported for implementing a Double-Ended Queue?
1
counter
2
collections
3
random
4
numpy
11
PYQ 2024
medium
computer-science ID: cuet-ug-
Which method moves a file pointer to the nth character with respect to r position?
1
fp.seek(r)
2
fp.seek(n)
3
fp.seek(n, r)
4
seek(n, r).fp
12
PYQ 2024
medium
computer-science ID: cuet-ug-
Consider the following code and specify the correct order of the statements to be written:
Code:
(A) f.write(”CUET EXAMINATION”)
(B) f=open(”CUET.TXT”, ”w”)
(C) print(”Data is Written Successfully”)
(D) f.close()
Choose the correct answer from the options given below:
Code:
(A) f.write(”CUET EXAMINATION”)
(B) f=open(”CUET.TXT”, ”w”)
(C) print(”Data is Written Successfully”)
(D) f.close()
Choose the correct answer from the options given below:
1
(A), (B), (C), (D)
2
(B), (A), (C), (D)
3
(B), (D), (C), (A)
4
(B), (D), (A), (C)
13
PYQ 2024
medium
computer-science ID: cuet-ug-
Match List-I with List-II:
| List-I | List-II |
| (A) readline() | (I) Writes a sequence of strings to the file |
| (B) writelines() | (II) Reads a single line from the file |
| (C) seek() | (III) Force any buffered output to be written to the file |
| (D) flush() | (IV) Moves the file pointer to the specified position |
1
(A) - (I), (B) - (II), (C) - (III), (D) - (IV)
2
(A) - (II), (B) - (I), (C) - (IV), (D) - (III)
3
(A) - (II), (B) - (I), (C) - (III), (D) - (IV)
4
(A) - (III), (B) - (IV), (C) - (I), (D) - (II)
14
PYQ 2025
medium
computer-science ID: cuet-ug-
__________ is the process of transforming data or an object in memory (RAM) to a stream of bytes called byte streams.
1
read()
2
write()
3
Pickling
4
De-serialization
15
PYQ 2025
medium
computer-science ID: cuet-ug-
Arrange the following Python code segments in order with respect to exception handling: (A) except ZeroDivisionError:
\hspace{0.5cm} print("Zero denominator not allowed")
(B) finally:
\hspace{0.5cm} print("Over and Out")
(C) try:
\hspace{0.5cm} n = 50
\hspace{0.5cm} d = int(input("enter denominator"))
\hspace{0.5cm} q = n/d
\hspace{0.5cm} print("division performed")
(D) else:
\hspace{0.5cm} print("Result=", q)
\hspace{0.5cm} print("Zero denominator not allowed")
(B) finally:
\hspace{0.5cm} print("Over and Out")
(C) try:
\hspace{0.5cm} n = 50
\hspace{0.5cm} d = int(input("enter denominator"))
\hspace{0.5cm} q = n/d
\hspace{0.5cm} print("division performed")
(D) else:
\hspace{0.5cm} print("Result=", q)
1
(C), (A), (B), (D)
2
(C), (A), (D), (B)
3
(B), (A), (D), (C)
4
(C), (B), (D), (A)
16
PYQ 2025
medium
computer-science ID: cuet-ug-
Identify the correct code to read data from the file \texttt{notes.dat} in a binary file:
1
import pickle f1=open("notes.dat","r") data=pickle.load(f1) print(data) f1.close()
2
import pickle f1=open("notes.dat","rb") data=f1.load() print(data) f1.close()
3
import pickle f1=open("notes.dat","rb") data=pickle.load(f1) print(data) f1.close()
4
import pickle f1=open("notes.dat","rb") data=f1.read() print(data) f1.close()
17
PYQ 2025
medium
computer-science ID: cuet-ug-
Identify the correct python statement to open a text file \texttt{"data.txt"} in both read and write mode.
1
file.open("data.txt")
2
file.open("data.txt","r+")
3
file.open("data.txt","rw")
4
file.open("data.txt","rw+")
18
PYQ 2025
medium
computer-science ID: cuet-ug-
Matplotlib library can be installed using pip command. Identify the correct syntax from the following options.
1
pip install matplotlib.pyplot
2
pip install matplotlib.pyplot
3
pip install matplotlib.pyplot as plt
4
pip install matplotlib
19
PYQ 2025
medium
computer-science ID: cuet-ug-
Given the following statement: import matplotlib.pyplot as plt 'plt' in the above statement is .............. name.
1
key
2
alias
3
variable
4
function