File Handling || Multiple Choice Questions || Class 12



1. To open a file c:\test.txt for reading, we should give the statement:

(a) filel = open("c:\ test.txt", "r")

(b) file1 = open("c:\\ test.txt", "r")

(c) file = open(file = "c:\ test.txt", "r")

(d) file1 = open(file = "c:\\s test.txt", "r")

2. To open a file c:\ test.txt for writing, we should use the statement:

(a) fobj = open("c:\test.txt", "w")

(b) fobj = open("c:\\ test.txt", "w")

(c) fobj = open(file = "c:\ test.txt", "w")

(d) fobj = open(file = "c:\\ test.txt", "w")

3. To open a file c:\ test.txt for appending data, we can give the statement:

(a) fobj = open("c:\\ test.txt", "a")

(b) fobj = open("c:\\ test.txt", "rw")

(c) fobj = open(file = "c:\test.txt", "w")

(d) fobj = open(file = "c:\\ test.txt", "w")

4. Which of the following statements is/are true?

(a) When you open a file for reading, if the file does not exist, an error occurs.

(b) When you open a file for writing, if the file does not exist, a new file is created.

(c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

(d) All of the above.

5. To read two characters from a file object from, the command should be:

(a) fobj.read(2)

(b) fobj.read()

(c) fobj.readline()

(d) fobj.readlines()

6. To read the entire contents of the file as a string from a file object fobj, the command should be:

(a) fobj.read(2)

(b) fobj.read()

(c) fobj.readline()

(d) fobj.readlines()

7. What will be the output of the following snippet?

f = None

for i in range (5):

with open ("data.txt", "W") as f:

if i > 2:

break

print (f.closed)

(a) True

(b) False

(c) None

(d) Error

8. To read the next line of the file from a file object fobj, we use:

(a) fobj.read(2)

(b) fobj.read()

(c) fobj.readline()

(d) fobj.readlines()

9. To read the remaining lines of the file from a file object fobj, we use:

(a) fobj.read(2)

(b) fobj.read()

(c) fobj.readline()

(d) fobj.readlines

10. The readlines() method returns:

(a) String

(b) A list of integers

(c) A list of single characters

(d) A list of lines

11. Which module is required to use the built-in function dump( )?

(a) math

(b) flush

(c) pickle

(d) unpickle

12. Which of the following functions is used to write data in the binary mode?

(a) write

(b) output

(c) dump

(d) send

13. Which is/are the basic I/O (input-output) stream(s) in file?

(a) Standard Input

(b) Standard Output

(c) Standard Errors

(d) All of the above

14. Which of the following is the correct syntax of file.writelines()?

(a) file.writelines(sequence)

(b) fobj.writelines()

(c) fobj.writelines(sequence)

(d) fobj.writeline()

15. In file handling, what do the terms "r" and "a" stand for?

(a) read, append

(b) append, read

(iii) write, append

(d) None of the above

16. Which of the following is not a valid mode to open a file?

(a) ab

(b) rw

(c) r+

(d) w+

17. Which statement is used to change the file position to an offset value from the start?

(a) fp.seek(offset, 0)

(b) fp.seek(offset, 1)

(c) fp.seek(offset, 2)

(d) None of the above

18. The difference between r+ and w+ modes is expressed as?

(a) No difference

(b) In r+ mode, the pointer is initially placed at the beginning of the file and the pointer is at the end for w+

(c) In w+ mode, the pointer is initially placed at the beginning of the file and the pointer is at the end for r+

(d) Depends on the operating system

19. What does CSV stand for?

(a) Cursor Separated Variables

(b) Comma Separated Values

(c) Cursor Separated Values

(d) Cursor Separated Version

20. Which module is used for working with CSV files in Python?

(a) random

(b) statistics

(c) csv

(d) math

21. Which of the following modes is used for both writing and reading from a binary file?

(a) wb+

(b) w

(c) wb

(d) w+

22. Which statement is used to retrieve the current position within the file?

(a) fp.seek()

(b) fp.tell()

(c) fp.loc

(d) fp.pos

23. What happens if no arguments are passed to the seek() method?

(a) file position is set to the start of file

(b) file position is set to the end of file

(c) file position remains unchanged

(d) results in an error

24. Which of the following modes will refer to binary data?

(a) r

(b) w

(c) +

(d) b

25. Every record in a CSV file is stored in reader object in the form of a list using which method?

(a) writer()

(b) append()

(c) reader()

(d) list()

26. Information stored on a storage device with a specific name is called a _____.

(a) array

(b) dictionary

(c) file

(d) tuple

27. Which of the following format of files can be created programmatically through Python to some data?

(a) Data files

(b) Text files

(c) Video files

(d) Binary files

28. To open a file c:\ss.txt for appending data, we use

(a) file = open("c:\\ss.txt", "a")

(b) file = open("c:\\ss.txt", "rw")

(c) file = open(r"c\ss.txt", "a")

(d) file = open(file = "c:\ss.txt", "w")

(e) file = open(file = "c\\ss.txt", "w")

(f) file = open("c\ res.txt")

29. To read the next line of the file from a file object infi, we use

(a) infi.read(all)

(b) infi.read()

(c) infi.readline()

(d) infi.readlines()

30. To read the remaining lines of the file from a file object infi, we use

(a) infi.read(all)

(b) infi.read()

(c) infi.readline()

(d) infi.readlines()

31. The readlines() method returns

(a) str

(b) a list of lines

(c) a list of single characters

(d) a list of integers

32. Which of the following mode will refer to binary data?

(a) r

(b) w

(c) +

(d) b

33. In file handling, what does this term means "r, a"?

(a) read, append

(b) append, read

(c) all of the mentioned

(d) none of these

34. Which function is used to read all the characters?

(a) read()

(b) read characters()

(c) readall()

(d) readchar()

35. Which function is used to read single line from file?

(a) readline()

(b) readlines()

(c) readstatement( )

(d) readfulline()

36. Which function is used to write all the characters?

(a) write()

(b) writecharacters()

(c) writeall()

(d) writechar()

37. Which function is used to write a list of strings in a file?

(a) writeline()

(b) writelines()

(c) writestatement()

(d) writefullline()

38. Which of the following is modes of both writing and reading in binary format in file?

(a) wb+

(b) w

(c) wb

(d) w+

39. Which of the following is not a valid mode to open a file?

(a) ab

(b) rw

(c) r+

(d) w+

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

(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.

14 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. if answer key was closer to question , it would be easy to refer !

    ReplyDelete
  2. These are from which book?

    ReplyDelete
  3. now new questions provided ,except few, but the answer are different thanks for giving new type of answers

    ReplyDelete
  4. Please add more questions asap as Term 1 board examination is just gonna be MCQs.

    ReplyDelete
  5. Thank you. The questions are really mind boggling (;

    ReplyDelete
  6. please, need more questions :)

    ReplyDelete
  7. great questions, need more though :)

    ReplyDelete
  8. To read 5 bytes from a file, the statement is

    ReplyDelete
  9. Update your content to the latest 2023-24 edition Sumita Arora
    Most of the questions aren't matching

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post