Professional Documents
Culture Documents
XII Computer Science File Handling MCQ
XII Computer Science File Handling MCQ
(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.
(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines()
(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines()
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
(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
(a) write
(b) output
(c) dump
(d) send
(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) ab
(b) rw
(c) r+
(d) w+
(a) fp.seek(offset, 0)
(b) fp.seek(offset, 1)
(c) fp.seek(offset, 2)
(d) None of the above
(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) 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+
(a) fp.seek()
(b) fp.tell()
(c) fp.loc
(d) fp.pos
(a) writer()
(b) append()
(c) reader()
(d) list()
(a) array
(b) dictionary
(c) file
(d) tuple
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()
(a) str
(b) a list of lines
(c) a list of single characters
(d) a list of integers
(a) r
(b) w
(c) +
(d) b
33. In file handling, what does this term means "r, a"?
(a) read()
(b) read characters()
(c) readall()
(d) readchar()
(a) readline()
(b) readlines()
(c) readstatement( )
(d) readfulline()
(a) write()
(b) writecharacters()
(c) writeall()
(d) writechar()
(a) writeline()
(b) writelines()
(c) writestatement()
(d) writefullline()
(a) wb+
(b) w
(c) wb
(d) w+
(a) ab
(b) rw
(c) r+
(d) w+
(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.
Answers:
1. b
2. b
3. a
4. d
5. a
6. b
7. a
8. c
9. d
10. d
11. c
12. c
13. d
14. c
15. a
16. b
17. a
18. b
19. b
20. c
21. a
22. b
23. d
24. d
25. c
26. c
27. b, d
28. a, c
29. c
30. d
31. b
32. d
33. a
34. a
35. a
36. a
37. b
38. a
39. b
40. B
FILL IN THE BLANKS
1. _____ in Python are interpreted as a sequence or stream of
bytes stored on some storage media.
10. The _____ statement automatically closes the file after the
processing on the file gets over.
11. The read() function reads data from the _____ of a file.
13. The readlines() returns a list of lines from the file till _____.
14. The _____ method reads 'n' characters from the file.
21. _____ is a string method that joins all values of each row
with comma separator in CSV.
23. To end all the file contents in the form of a list, _____
method may be used.
28. The two types of data files can be _____ files and _____ files.
30. The _____ file mode will open a file for read and write
purpose.
31. The _____ file mode will open a file for write and read
purpose.
32. To close an open file, _____ method is used.
33. To read all the file contents in form of a list, ______ method
is used.
Answers:
1. Files
2. open()
3. read ('r'), write ('w'), append ('a')
4. writelines()
5. close()
6. getcwd()
7. rename()
8. remove()
9. binary
10. with
11. (beginning)
12. dump(), load()
13. end of file (EOF)
14. read(n)
15. flush()
16. CSV
17. seek()
18. dump()
19. load()
20. import csv
21. join()
22. line_num
23. readlines()
24. writelines()
25. flush()
26. read
27. file mode
28. text, binary
29. file handle
30. r+
31. w+ or a+
32. close()
33. readlines()
34. writelines()
35. flush()
TRUE OR FALSE
7. When you open a file in read mode, the given file must exist in
the folder, otherwise Python will raise FileNotFound error.
16. CSV module can handle CSV files correctly regardless of the
operating system on which the files were created.
17. CSV module gets automatically imported into your program for
reading a CSV file.
20. Every record in a CSV file is stored in reader object in the form
of a list.
23. tell() method of Python tells us the current position within the
file.
24. The offset argument to seek() method indicates the number of
bytes to be moved.
26. When you open a file for reading, if the file does not exist, an
error occurs.
27. When you open a file for writing, if the file does not exist, an
error occurs.
28. When you open a file for writing, if the file exists, the existing
file is overwritten with the new file.
29. The absolute paths are from the topmost level of the directory
structure.
31. The relative path for a file always remains same even after
changing the directory.
32. The types of operations that can be carried out on a file depends
upon the file mode a file is opened in.
33. If no path is given with a file name in the file open(), then the
file must exist in current directory.
35. Python automatically flushes the file buffers before closing a file
with close() function.
Answers:
1. True
2. False
3. True
4. False
5. False
6. True
7. True
8. False
9. False
10. True
11. False
12. True
13. False
14. True
15. True
16. True
17. False
18. True
19. False
20. True
21. True
22. True
23. True
24. True
25. False
26. True
27. False
28. True
29. True
30. True
31. False
32. True
33. True
34. False
35. True