0% found this document useful (0 votes)
132 views10 pages

File Handling MCQ-1-10

Uploaded by

nareshprakash65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views10 pages

File Handling MCQ-1-10

Uploaded by

nareshprakash65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Name of the Chapter- DATA FILE HANDLING

Question Question Content Learning Objective(if


No Provided)
Q1. Suppose content of ‘mytext.txt’ file is: Knowledge

What will be the output of the following code?


file = open(“mytext.txt”, ‘r’)
txt = file.read()
print(file.read(10))

(A) The key to


(B) obstacles.
(C) Error
(D No Output
Q2. Consider the following directory structure: Application

There are three directories under root directory ‘Admin’.


The current working directory is Final. Identify the
relative path name for file ‘Result1.xlsx’.
(A) .\Result1.xlsx
(B) Admin\Final\First Term\Result1.xlsx
(C) ..\First Term\Result1.xlsx
(D) First Term\Result1.xlsx

Q3. Which of the following statements is correct regarding Understanding


file access modes?
(A) In ‘r’ mode, we can read and write data from/in the
file.
(B) In ‘a’ mode, the existing data will be over-written if
the file exists.
(C) In ‘w’ mode, the data in the file is retained and new
data will be appended to the end.
(D) In ‘a+’ mode, both reading and writing operations can
take place and new data is appended to the end of the
existing file.

Q4. Consider a statement Understanding


fileobj = open(“myblog.txt”, ‘r’)
Which of the following options can be used to print the
last line of a text file ‘myblog.txt’?
(A) print(fileobj.readlines() -1)
(B) disp = fileobj.readlines()
print(disp[-1])
(C) print(fileobj.readlines(-1))
(D) print(fileobj.read(-1))

Q5. Which of the following statements is used to open a text Understanding


file to add new contents at the end of the already existing
text file named ‘mydiary.txt’?
(i) with open(“’mydiary.txt”, ‘w’) as fileobj:
(ii) fileobj = open(“mydiary.txt”, ‘a’)
(iii) with open(“mydiary.txt”,’a’) as fileobj:
(iv) with open(“mydiary”, ‘r+’) as fileobj:

(A) Only (i)


(B) Only (ii)
(C) Both (ii) and (iii)
(D) Both (i) and (iv)

Q6. “The information is stored in machine-readable format Understanding


and pickle module is used for reading and writing
data from/in the file.”
Identify the type of file discussed in the above lines?
(A) Text files
(B) CSV files
(C) Binary file
(D) All of the above

Q7. Assume that you are writing in a text file; now you want Knowledge
to identify where the cursor is currently at in the
file. Which function will you use for the same?
(A) seek()
(B) hide()
(C) tell()
(D) type()
Q8. Consider the statements given below: Evaluation
Fileobj = open(“Report.txt”, ‘r’)
Fileobj.seek(25,0)
Choose the statement that best explains the second
statement.
(A) It will place the pointer at 25 bytes ahead of the
current file pointer position.
(B) It will place the pointer at 25 bytes behind from the
end-of file.
(C) It will place the pointer at 25 bytes from the
beginning of the file.
(D) It returns 25 characters from the 0th index.

Q9. To read 4th line from text file, which of the following Knowledge
statement is true?
(A) dt = f.readlines();print(dt[3])
(B) dt=f.read(4) ;print(dt[3])
(C) dt=f.readline(4);print(dt[3])
(D) All of these

Q10. Which of the following groups of functions belongs to Application


CSV module?
(A) reader(), writer()
(B) readlines(), writelines()
(C) writerow(), read()
(D) writer(), readline()

Q11. Which is/are the basic I/O (input-output) stream(s) in Application


file?

(A) Standard Input


(B) Standard Output
(C) Standard Errors
(D) All of the above
Q12. Consider the content of the file ‘Story.txt’: Application

What is the output of the following code?


Fileobj = open("story.txt", 'r')
S1= Fileobj.read(20)
S2= Fileobj.tell()
Fileobj.seek(34,0)
S3= Fileobj.read(20)
print(S3)

(A) The Tortoise meanwhi


(B) slowly but steadily
(C) Hare was sleeping
(D) he Tortoise in time

Q13. Consider a file “online.txt” Evaluation

What will be the output of the following code?


fileobj=open('online.txt','r')
count = 0
l=fileobj.readline()
for i in l:
if 'o' in i:
count=count+1
print(count)
fileobj.close()

(A) 10
(B) 8
(C) 9
(D) 20

Q14. Which function is used to write all the characters? Understanding

(A) write()
(B) writecharacters()
(C) writeall()
(D) writechar()

Q15. What is the difference between r+ and w+ modes? Knowledge

(A) No difference.
(B) In r+ mode, the pointer is initially placed at the
beginning of the file and for w+, the pointer is placed at
the end.
(C) In w+ mode, the pointer is initially placed at the
beginning of the file and for r+, the pointer is placed at
the end.
(D) Depends on the operating system.

Q16 Information stored on a storage device with a specific


name. is called a
A. Array
B. Dictionary
C. file
D. tuple

Q17 EOL stands for


A. End of Lines
B. End Of Line
C. End Of List
D. End Of Location

Q18 Which of the following file types allows to store large


data files in the computer memory?
A. Text Files
B. Binary Files
C. CSV Files
D. None of these

Q19 Which of the following functions transfer the data to file


before closing the file?
A. flush()
B. close()
C. open()
D. fflush()

Q20 Which of the following is not a known file type?


A. csv
B. pdf
C. txt
D. txp

Q21 Which of the following not a valid file extension for file
student?
A. student.txt
B. student.cvc
C. student.dat
D. student.pdf

Q22 Which of the following is not a correct statement for


binary files?
A. Easy for carrying data into buffer
B. Much faster than other file systems
C. Every line ends with new line character ‘\n’
D. Characters translation is not required

Q23 Which of the following file types can be opened with


notepad as well as ms excel?
A. Text Files
B. CSV Files
C. Binary Files
D. None of these

Q24 Which of the following format of files can be created


programmatically through python to store some data?
A. Pdf file
B. Audio file
C. Binary file
D. Video file

Q25 Which file can open in any text editor and is in human
readable form?
A. Binary files
B. Text files
C. Data files
D. d. Video files

Q26 is a file format which stores records separated


by comma.
A. .tsv
B. .csv
C. .py
D. .bin
Q27 The CSV files can be operated by software.
A. Spreadsheet
B. Notepad
C. MS Excel
D. All of the above

Q28 Which of the following parameter needs to be added with


open function to avoid blank row followed file each row
in CSV file?
A. delimiter
B. newline
C. writer, delimiter
D. file object

Q29 12. Default EOL character in Python.


A. ‘\n’
B. ‘\r’
C. ‘’
D. ‘\t’

Q30 Trying to open a binary file using a text editor will show:
A. Garbage values
B. ASCII values
C. Binary character
D. Unicodes

Q31 Choose the correct syntax to open a file in write mode. KNOWLEDGE AND
(A) f.open(“file.txt”,’w’) UNDERSTANDING
(B) f = open(“file.txt”)
(C) f = open(“file.txt”,’w’)
(D) f = open(“file.txt”, ‘r’)
Q32 Choose the correct syntax to open a file in append mode. KNOWLEDGE AND
(A) with open(“file.txt”, “a”) as f : UNDERSTANDING
(B) with open(“file.txt”) as “f”
(C) with open(“file.txt”, “a”) as f
(D) with open(“file.txt”, “w”) as f :
Q33 Which of the following is not a valid file access mode? KNOWLEDGE AND
(A) a+ UNDERSTANDING
(B) r
(C) w
(D) b+
Q34 Choose the correct syntax to close a file. KNOWLEDGE AND
(A) f.closed UNDERSTANDING
(B) f.close()
(C) f.closed()
(D) f.close
Q35 Which method is used to write multiple strings/lines in a KNOWLEDGE AND
text file? UNDERSTANDING
(A) write()
(B) writeline()
(C) writelines()
(D) writesingle()
Q36 Which method is used to write a single string/line in a KNOWLEDGE AND
text file? UNDERSTANDING
(A) write()
(B) writeline()
(C) writelines()
(D) writesingle()
Q37 Which of the following statements is correct? KNOWLEDGE AND
(A) In r+ mode, a file opens for both reading and writing UNDERSTANDING
if it already exists. The file pointer placed at the
beginning of the file.
(B) In w+ mode, a file opens for both writing and
reading. Overwrites the existing file if the file exists. If
the file does not exist, create a new file for reading and
writing.
(C) Both of the above
(D) None of the above
Q38 By default, in which mode a file open. KNOWLEDGE AND
(A) r UNDERSTANDING
(B) w
(C) a
(D) None of the above
Q39 While using an open function in which mode a text file APPLICATION
will be created, if it does not exist already.
(A) r+
(B) w
(C) Both of the above
(D) None of the above
Q40 While using an open function in which mode a text file APPLICATION
will not be created, if it does not exist already.
(A) r+
(B) r
(C) Both of the above
(D) None of the above
Q41 Which of the following iterable objects can be passed to APPLICATION
the writelines() method for writing multiple lines/strings
in a text file.
(A) list
(B) tuple
(C) Both of the above
(D) None of the above
Q42 Which of the following is not a correct statement? APPLICATION
(A) write and append modes opens file for writing.
(B) In both modes file pointer for existing file sets to
beginning of file, when opened.
(C) In append mode existing data do not get overwritten,
whereas in writing mode existing data gets overwritten.
(D) By adding ‘+’ symbol both can be able to open files
in reading mode also.
Q43 A user opened a file using code : f = open(“story.txt”,’r’) ANALYSIS,
But the file “story.txt” does not get opened. Find the EVALUATION AND
appropriate reason for not opening the file. CREATION
(A) There is a syntax error in the code.
(B) File pointer name is not correct.
(C) User need to include the absolute path of file location.
(D) File does not exist.
Q44 Consider the code: ANALYSIS,
lines = ['This is line 1', 'This is line 2'] EVALUATION AND
with open('readme.txt', 'w') as f: CREATION
f.writelines(lines)
Which of the following statements is true regarding the
content of the file ‘readme.txt’?
(A) Both strings of list lines will be written in two
different lines in the file ‘readme.txt’.
(B) Both strings of list lines will be written in the same
line in the file ‘readme.txt’.
(C) string 1 of list lines will overwrite string 2 of list lines
in the file ‘readme.txt’.
(D) string 2 of list lines will overwrite string 1 of list lines
in the file ‘readme.txt’.
Q45 Consider the code: ANALYSIS,
lines = ['This is line 1', 'This is line 2'] EVALUATION AND
with open('readme.txt', 'w') as f: CREATION
for line in lines:
f.write(line+’\n’)
Which of the following statements is true regarding the
content of the file ‘readme.txt’?
(A) Both strings of list lines will be written in two
different lines in the file ‘readme.txt’.
(B) Both strings of list lines will be written in the same
line in the file ‘readme.txt’.
(C) string 1 of list lines will overwrite string 2 of list lines
in the file ‘readme.txt’.
(D) string 2 of list lines will overwrite string 1 of list lines
in the file ‘readme.txt’.
Q46 What are the file types in Python?
(A) Text File Understanding
(B) TSV File
(C) CSV File
(D) All of the above
Q47. Which command is used to open a text file in Python in Analysis
reading mode?
(A) F = open( )
(B) F = open(“Data.Txt”,”w”)
(C) F = open(“Data.Txt,”r”)
(D) All of the Above
Q48 What is the use of File Object? Knowledge
(A) File Object Serves as a link to a file
(B) File Objects are used to read and write data to the file
(C) A file Object is a reference to a file on disk
(D) All of the above
Q49 Which is the default mode to open a file? Knowledge
(A) read mode
(B) r+ mode
(C) write mode
(D) w+ mode
Q50 Which mode creates a new file, when open file ? Understanding
(A) w+ mode
(B) a mode
(C) a+ mode
(D) All of the above

You might also like