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,
1. What is the primary purpose of storing data in files?
2. Where are files stored in a computer system?
3. Which of the following is a text file extension?
4. What is the main difference between text and binary files?
5. What happens if a binary file is opened in a text editor?
6. Which of the following is an example of a binary file?
7. What is the default EOL character in Python?
8. Which encoding scheme is commonly used for text files?
9. Which function is used to open a file in Python?
10. What is the default mode for opening a file?
11. Which mode is used to open a file for both reading and writing?
12. What happens if a file opened in ‘w’ mode already exists?
13. Which attribute returns the access mode of a file?
14. How is a file closed in Python?
15. What is the advantage of using the with clause to open a file?
16. Which method is used to write a single string to a file?
17. What does the write() method return?
18. How can numeric data be written to a text file?
19. Which method is used to write multiple strings to a file?
20. What is the purpose of the flush() method?
21. Which method reads a specified number of bytes from a file?
22. What happens if no argument is passed to the read() method?
23. Which method reads one complete line from a file?
24. What does the readlines() method return?
25. How can you read a file line by line using a loop?
26. What does the split() function do when reading a file?
27. Which method returns the current position of the file object?
28. What is the purpose of the seek() method?
29. What is the default reference point for the seek() method?
30. How do you move the file object to the 10th byte from the beginning?
31. What happens if a file opened in ‘a’ mode does not exist?
32. Which mode is used to open a file for both reading and writing without overwriting existing content?
33. How can you iterate over all lines in a file?
34. What is the output of fileobject.tell() after writing data to a file?
35. What is the purpose of the pickle module?
36. Which method is used to write Python objects to a binary file?
37. Which method is used to read Python objects from a binary file?
38. What mode is used to open a binary file for writing?
39. What happens if a binary file is corrupted?
40. Which exception is raised when the end of a binary file is reached during unpickling?
41. What is serialization?
42. What is deserialization?
43. Which module is required for pickling and unpickling?
44. What is the output of file.closed if the file is open?
45. Which method is used to forcefully write buffer contents to a file?
46. What is the purpose of the splitlines() method?
47. Which of the following is not a file attribute?
48. What is the correct way to open a file for reading and writing in binary mode?
49. What is the correct syntax for the with clause?
50. What is the purpose of the io module in Python?
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.
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.
53.Assertion (A): The open() function returns a file object. Reason (R): This file object is used to perform read or write operations.
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.
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.
56. Assertion (A): The writelines() method requires a list or tuple of strings. Reason (R): It adds newline characters between each string automatically.
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.
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.
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.
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.
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.
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.
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.
64. Assertion (A): Pickling converts a Python object into a byte stream. Reason (R): It is useful for storing Python objects in binary files.
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().
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.
67. Assertion (A): All Python objects can be pickled. Reason (R): The pickle module can serialize even open file objects and sockets.
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.
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.
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.

No comments: