google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 File Handling In Python Programming Mcq | File Handling In Python Class 12 Mcq - 2nd puc computer science

File Handling In Python Programming Mcq | File Handling In Python Class 12 Mcq

 file handling in python programming mcq,file handling in python class 12 mcq,file handling in python class 12 mcq with answers,file handling in python class 12 mcq online test,file handling mcq in python,file handling mcq in python with answers,mcq on file handling in python class 12,file handling in python class 12 mcqs,file handling question in python for class 12,file handling questions in python for class 12,file handling in python class 12 mcq pdf,file handling in python class 12 mcq with answers pdf,

File Handling In Python Programming Mcq

1. What is the primary purpose of storing data in files?





ANSWER= B) To permanently store data for later access

2. Where are files stored in a computer system?





ANSWER= B) Secondary storage media

3. Which of the following is a text file extension?





ANSWER= A) .txt

4. What is the main difference between text and binary files?





ANSWER= C) Text files consist of ASCII/Unicode characters

5. What happens if a binary file is opened in a text editor?





ANSWER= B) It shows garbage values

6. Which of the following is an example of a binary file?





ANSWER= C) A .docx file

7. What is the default EOL character in Python?





ANSWER= B) \n

8. Which encoding scheme is commonly used for text files?





ANSWER= A) ASCII

9. Which function is used to open a file in Python?





ANSWER= B) open()

10. What is the default mode for opening a file?





ANSWER= A) Read mode (‘r’)

11. Which mode is used to open a file for both reading and writing?





ANSWER= B) ‘w+’

12. What happens if a file opened in ‘w’ mode already exists?





ANSWER= B) The existing content is overwritten

13. Which attribute returns the access mode of a file?





ANSWER= B) file.mode

14. How is a file closed in Python?





ANSWER= A) file.close()

15. What is the advantage of using the with clause to open a file?





ANSWER= B) It automatically closes the file

16. Which method is used to write a single string to a file?





ANSWER= B) write()

17. What does the write() method return?





ANSWER= A) The number of characters written

18. How can numeric data be written to a text file?





ANSWER= B) By converting it to a string first

19. Which method is used to write multiple strings to a file?





ANSWER= A) writelines()

20. What is the purpose of the flush() method?





ANSWER= B) To clear the buffer and write contents to the file

21. Which method reads a specified number of bytes from a file?





ANSWER= A) read()

22. What happens if no argument is passed to the read() method?





ANSWER= B) It reads the entire file

23. Which method reads one complete line from a file?





ANSWER= B) readline()

24. What does the readlines() method return?





ANSWER= B) A list of strings

25. How can you read a file line by line using a loop?





ANSWER= A) Using readline() in a while loop

26. What does the split() function do when reading a file?





ANSWER= B) Splits each line into a list of words

27. Which method returns the current position of the file object?





ANSWER= B) tell()

28. What is the purpose of the seek() method?





ANSWER= B) To move the file object to a specific position

29. What is the default reference point for the seek() method?





ANSWER= A) Beginning of the file (0)

30. How do you move the file object to the 10th byte from the beginning?





ANSWER= A) seek(10, 0)

31. What happens if a file opened in ‘a’ mode does not exist?





ANSWER= B) A new file is created

32. Which mode is used to open a file for both reading and writing without overwriting existing content?





ANSWER= C) ‘a+’

33. How can you iterate over all lines in a file?





ANSWER= C) Both a and b

34. What is the output of fileobject.tell() after writing data to a file?





ANSWER= B) The current byte position of the file object

35. What is the purpose of the pickle module?





ANSWER= B) To serialize and deserialize Python objects

36. Which method is used to write Python objects to a binary file?





ANSWER= B) dump()

37. Which method is used to read Python objects from a binary file?





ANSWER= B) load()

38. What mode is used to open a binary file for writing?





ANSWER= B) ‘wb’

39. What happens if a binary file is corrupted?





ANSWER= B) It becomes unreadable

40. Which exception is raised when the end of a binary file is reached during unpickling?





ANSWER= B) EOFError

41. What is serialization?





ANSWER= A) Converting Python objects to byte streams

42. What is deserialization?





ANSWER= A) Converting byte streams to Python objects

43. Which module is required for pickling and unpickling?





ANSWER= B) pickle

44. What is the output of file.closed if the file is open?





ANSWER= B) False

45. Which method is used to forcefully write buffer contents to a file?





ANSWER= B) flush()

46. What is the purpose of the splitlines() method?





ANSWER= B) To split a string into a list of lines

47. Which of the following is not a file attribute?





ANSWER= C) file.size

48. What is the correct way to open a file for reading and writing in binary mode?





ANSWER= A) open(“file.dat”, “r+b”)

49. What is the correct syntax for the with clause?





ANSWER= A) with open(“file.txt”, “r”) as f:

50. What is the purpose of the io module in Python?





ANSWER= A) To handle file operations

51. Assertion (A): A text file can be opened and read using a text editor. Reason (R): Text files store data in the form of ASCII or Unicode characters.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

52. Assertion (A): Binary files can be edited easily using Notepad or any text editor. Reason (R): Binary files store information using human-readable characters.





ANSWER= D) A is false, but R is true

53.Assertion (A): The open() function returns a file object. Reason (R): This file object is used to perform read or write operations.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

54. Assertion (A): Files should be closed using the close() method after operations. Reason (R): Closing a file ensures that all data is flushed and memory is freed.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

55. Assertion (A): The write() method automatically adds a newline character at the end of the string. Reason (R): It is designed to make each write call write a new line.





ANSWER= D) A is false, but R is true

56. Assertion (A): The writelines() method requires a list or tuple of strings. Reason (R): It adds newline characters between each string automatically.





ANSWER= C) A is true, but R is false

57. Assertion (A): Opening a file in 'w' mode erases its existing contents. Reason (R): In this mode, the file pointer is placed at the end of the file.





ANSWER= C) A is true, but R is false

58. Assertion (A): The read() method reads the complete file when no parameter is passed. Reason (R): It returns a list of strings when the file is completely read.





ANSWER= C) A is true, but R is false

59. Assertion (A): The readline() method reads the file until a newline character is found. Reason (R): It always reads the complete file in one go.





ANSWER= C) A is true, but R is false

60. Assertion (A): The readlines() method returns a list containing each line as an element. Reason (R): This method is useful when we want to iterate through lines as list elements.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

61. Assertion (A): The tell() function returns the current byte position of the file object. Reason (R): It is helpful when tracking file offset during file operations.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

62. Assertion (A): The seek() method is used to randomly access a file. Reason (R): It always moves the file pointer to the beginning of the file.





ANSWER= C) A is true, but R is false

63. Assertion (A): The with statement is preferred in Python for file handling. Reason (R): It automatically closes the file when execution goes out of scope.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

64. Assertion (A): Pickling converts a Python object into a byte stream. Reason (R): It is useful for storing Python objects in binary files.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

65. Assertion (A): The dump() method writes binary data to a file. Reason (R): The file must be opened in 'rb' mode to use dump().





ANSWER= C) A is true, but R is false

66. Assertion (A): The load() method is used for unpickling data from a binary file. Reason (R): It recreates the original Python object from the byte stream.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

67. Assertion (A): All Python objects can be pickled. Reason (R): The pickle module can serialize even open file objects and sockets.





ANSWER= D) A is false, but R is true

68. Assertion (A): A file opened using mode 'a+' allows both appending and reading. Reason (R): The file pointer is initially placed at the beginning of the file.





ANSWER= C) A is true, but R is false

69. Assertion (A): If a file opened using 'w' mode does not exist, it will be created. Reason (R): The 'w' mode only works on already existing files.





ANSWER= C) A is true, but R is false

70. Assertion (A): pickle.load() raises EOFError when end of file is reached. Reason (R): This helps to read binary files using a while loop and try-except block.





ANSWER= A) Both A and R are true, and R is the correct explanation of A

File Handling In Python Programming Mcq | File Handling In Python Class 12 Mcq File Handling In Python Programming Mcq | File Handling In Python Class 12 Mcq Reviewed by Vision Academy on July 08, 2025 Rating: 5

No comments:

CheckOut

Powered by Blogger.