Python Tutorial: File Handling-MCQ

Friday, 14 October 2022

File Handling-MCQ

 

Q1. Which statement will read 5 characters from a file(file object ‘f’)?





Ans. b. f.read(5)
Explain:-

 

Q2. Which function open file in python?





Ans. a. open( )
Explain:-

 

Q3. Processing of Text file is faster than binary files.(T/F)



Ans. b. False
Explain:-

 

Q4. Which mode create new file if the file does not exist?





Ans. c. Both of the above
Explain:-

 

Q5. Which statement will return one line from a file (file object is ‘f’)?





Ans. a. f.readline( )
Explain:-

 

Q6. Which symbol is used for append mode?





Ans. b. a
Explain:-

 

Q7. Which of the following will read entire content of file(file object ‘f’)?





Ans. b. f.read( )
Explain:-

 

Q8. Which function is used to read data from Text File?





Ans. a. read( )
Explain:-

 

Q9. EOF stands for _________________





Ans. a. End of File
Explain:-

 

Q10. readlines() method return _________





Ans. b. List
Explain:-

 

Q11. Which of the following options can be used to read the first line of a text file data.txt?





Ans. c. myfile = open(‘data.txt’); f.readline()
Explain:-

 

Q12. File in python is treated as sequence of ________________





Ans. a. Bytes
Explain:-

 

Q13. Which function is used to write data in binary mode?





Ans. d. dump
Explain:-

 

Q14. Which function is used to force transfer of data from buffer to file?





Ans. a. flush( )
Explain:-

 

Q15. 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?





Ans. d. f.readlines( )
Explain:-

 

Q16. Which statement will open file “data.txt” in append mode?





Ans. a. f = open(“data.txt” , “a”)
Explain:-

 

Q17. What is full form of CSV





Ans. b. Comma Separated Value
Explain:-

 

Q18. What is ‘f’ in the following statement?
f=open("Data.txt" , "r")





Ans. b. File Handle
Explain:-

 

Q19. readlines( ) function returns all the words of the file in the form of List. (T/F)
f=open("Data.txt" , "r")



Ans. b. False
Explain:-

 

Q20. Which of the following is an invalid mode of file opening?
f=open("Data.txt" , "r")





Ans. d. write and append mode
Explain:-

 

Q21. Identify the invalid mode from the following.
f=open("Data.txt" , "r")





Ans. c. ar+
Explain:-

 

Q22. The syntax of seek() is: file_object.seek(offset [, reference_point])
What is reference_point indicate?
f=open("Data.txt" , "r")





Ans. a. reference_point indicates the starting position of the file object
Explain:-

 

Q23. ______________ function returns the strings.)





Ans. c. Both of the above
Explain:-

 

Q24. Which of the following error is returned when we try to open a file in write mode which does not exist?





Ans. d. None of the above
Explain:-

 

Q25. ____________________ module is used for serializing and de-serializing any Python object structure.





Ans. a. pickle
Explain:-

No comments:

Post a Comment