0% found this document useful (0 votes)
228 views

Data File Handling in Python Class 12 - Mcqs

This document discusses various topics related to file handling in Python, including: 1) File types and modes for opening files, such as text (.txt) files, CSV files, and modes like 'r' for reading and 'w' for writing. 2) Functions for reading and writing file contents like open(), close(), read(), readline(), readlines(). 3) Key file handling concepts such as file objects, End of Line (EOL), seeking within a file. 4) Working with CSV files using the csv module and storing records in lists. 5) Opening files for different purposes on different operating systems using correct file paths. So in summary, it provides an overview

Uploaded by

Guru Murthy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
228 views

Data File Handling in Python Class 12 - Mcqs

This document discusses various topics related to file handling in Python, including: 1) File types and modes for opening files, such as text (.txt) files, CSV files, and modes like 'r' for reading and 'w' for writing. 2) Functions for reading and writing file contents like open(), close(), read(), readline(), readlines(). 3) Key file handling concepts such as file objects, End of Line (EOL), seeking within a file. 4) Working with CSV files using the csv module and storing records in lists. 5) Opening files for different purposes on different operating systems using correct file paths. So in summary, it provides an overview

Uploaded by

Guru Murthy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Data file handling in python class c.

CSV Files
12 – MCQs d. None of these
1 Every file has its own identity
7. Which of the following is nor a
associated with it. Which is known as
proper file access mode?

a. close
a. icon b. read
c. write
b. extension
d. append
c. format
8. To read 4th line from text file, which
d. file type of the following statement is true?
2 Which of the following is not a a. dt = f.readlines();print(dt[3])
known file type? b. dt=f.read(4) ;print(dt[3])
a. .pdf c. dt=f.readline(4);print(dt[3])
b. jpg d. All of these
c. mp3 9 Which of the following function
d. txp flushes the files implicitly?
3. In f=open(“data.txt”, “r”), r refers to a. flush()
__________. b. close()
a. File handle c. open()

b. File object d. fflush()


c. File Mode 10. Which of the following functions
d Buffer flushes the data before closing the file?
4. EOL stands for a. flush()
a. End Of Line b. close()
b. End Of List c. open()
c. End of Lines d. fflush()
d. End Of Location 11. To open a file c:\test.txt for
5. Which of the following file types reading, we should give the statement:
allows to store large data files in the (a) filel = open("c:\ test.txt", "r")
computer memory? (b) file1 = open("c:\\ test.txt", "r")
(c) file = open(file = "c:\ test.txt", "r")
a. Text Files (d) file1 = open(file = "c:\\s test.txt",
b. Binary Files "r")
c. CSV Files 12. To open a file c:\ test.txt for
d. None of these writing, we should use the statement:
6. Which of the following file types can (a) fobj = open("c:\test.txt", "w")
be opened with notepad as well as ms (b) fobj = open("c:\\ test.txt", "w")
excel? (c) fobj = open(file = "c:\ test.txt", "w")
a. Text Files (d) fobj = open(file = "c:\\ test.txt", "w")
b. Binary Files
13. To open a file c:\ test.txt for (a) fobj.read(2)
appending data, we can give the (b) fobj.read()
statement: (c) fobj.readline()
(a) fobj = open("c:\\ test.txt", "a") (d) fobj.readlines()
(b) fobj = open("c:\\ test.txt", "rw") For Answer Click Here
(c) fobj = open(file = "c:\test.txt", "w") 19. To read the remaining lines of the
(d) fobj = open(file = "c:\\ test.txt", "w") file from a file object fobj, we use:
14. Which of the following statements (a) fobj.read(2)
is/are true? (b) fobj.read()
(a) When you open a file for reading, if (c) fobj.readline()
the file does not exist, an error occurs. (d) fobj.readlines
(b) When you open a file for writing, if 20. The readlines() method returns:
the file does not exist, a new file is (a) String
created. (b) A list of integers
(c) When you open a file for writing, if (c) A list of single characters
the file exists, the existing file is (d) A list of lines
overwritten with the new file. 21. Which module is required to use
(d) All of the above. the built-in function dump( )?
15. To read two characters from a file (a) math
object from, the command should be: (b) flush
(a) fobj.read(2) (c) pickle
(b) fobj.read() (d) unpickle
(c) fobj.readline() 22. Which of the following functions is
(d) fobj.readlines() used to write data in the binary mode?
16. To read the entire contents of the (a) write
file as a string from a file object fobj, (b) output
the command should be: (c) dump
(a) fobj.read(2) (d) send
(b) fobj.read() 23. Which is/are the basic I/O (input-
(c) fobj.readline() output) stream(s) in file?
(d) fobj.readlines() (a) Standard Input
17. What will be the output of the (b) Standard Output
following snippet? (c) Standard Errors
f = None (d) All of the above
for i in range (5): For Answer Click Here
with open ("data.txt", "W") as f: 24. Which of the following is the
if i > 2: correct syntax of file.writelines()?
break (a) file.writelines(sequence)
print (f.closed) (b) fobj.writelines()
(a) True (c) fobj.writelines(sequence)
(b) False (d) fobj.writeline()
(c) None 25. In file handling, what do the terms
(d) Error "r" and "a" stand for?
18. To read the next line of the file (a) read, append
from a file object fobj, we use: (b) append, read
(iii) write, append 32. Which statement is used to
(d) None of the above retrieve the current position within the
26. Which of the following is not a file?
valid mode to open a file? (a) fp.seek()
(a) ab (b) fp.tell()
(b) rw (c) fp.loc
(c) r+ (d) fp.pos
(d) w+ 33. What happens if no arguments are
27. Which statement is used to change passed to the seek() method?
the file position to an offset value from (a) file position is set to the start of file
the start? (b) file position is set to the end of file
(a) fp.seek(offset, 0) (c) file position remains unchanged
(b) fp.seek(offset, 1) (d) results in an error
(c) fp.seek(offset, 2) 34. Which of the following modes will
(d) None of the above refer to binary data?
28. The difference between r+ and w+ (a) r
modes is expressed as? (b) w
(a) No difference (c) +
(b) In r+ mode, the pointer is initially (d) b
placed at the beginning of the file and 35. Every record in a CSV file is stored
the pointer is at the end for w+ in reader object in the form of a list
(c) In w+ mode, the pointer is initially using which method?
placed at the beginning of the file and (a) writer()
the pointer is at the end for r+ (b) append()
(d) Depends on the operating system (c) reader()
29. What does CSV stand for? (d) list()
(a) Cursor Separated Variables 36. Information stored on a storage
(b) Comma Separated Values device with a specific name is called a
(c) Cursor Separated Values _____.
(d) Cursor Separated Version (a) array
30. Which module is used for working (b) dictionary
with CSV files in Python? (c) file
(a) random (d) tuple
(b) statistics 37. Which of the following format of
(c) csv files can be created programmatically
(d) math through Python to some data?
31. Which of the following modes is (a) Data files
used for both writing and reading from (b) Text files
a binary file? (c) Video files
(a) wb+ (d) Binary files
(b) w 38. To open a file c:\ss.txt for
(c) wb appending data, we use
(d) w+ (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") 46. Which function is used to write all
(e) file = open(file = "c\\ss.txt", "w") the characters?
(f) file = open("c\ res.txt") (a) write()
39. To read the next line of the file (b) writecharacters()
from a file object infi, we use (c) writeall()
(a) infi.read(all) (d) writechar()
(b) infi.read() 77. Which function is used to write a
(c) infi.readline() list of strings in a file?
(d) infi.readlines() (a) writeline()
40. To read the remaining lines of the (b) writelines()
file from a file object infi, we use (c) writestatement()
(a) infi.read(all) (d) writefullline()
(b) infi.read() 48. Which of the following is modes of
(c) infi.readline() both writing and reading in binary
(d) infi.readlines() format in file?
41. The readlines() method returns (a) wb+
(a) str (b) w
(b) a list of lines (c) wb
(c) a list of single characters (d) w+
(d) a list of integers 49. Which of the following is not a
42. Which of the following mode will valid mode to open a file?
refer to binary data? (a) ab
(a) r (b) rw
(b) w (c) r+
(c) + (d) w+
(d) b 50. What is the difference between r+
43. In file handling, what does this and w+ modes?
term means "r, a"? (a) No difference.
(a) read, append
(b) append, read (b) In r+ mode, the pointer is initially
(c) all of the mentioned placed at the beginning of the file and
(d) none of these for w+, the pointer is placed at the
44. Which function is used to read all end.
the characters?
(c) In w+ mode, the pointer is initially
(a) read()
placed at the beginning of the file and
(b) read characters()
for r+, the pointer is placed at the end.
(c) readall()
(d) readchar()
(d) Depends on the operating system.
45. Which function is used to read
single line from file? Let’s Start
(a) readline() 51. We store Python programs written
(b) readlines() in script mode with a ________
(c) readstatement( ) extension.
(d) readfulline() 1. .file
2. .py
3. .pyfile 3. \t
4. .format 4. |n
52. A file is a 59. Trying to open a binary file using a
1. named location on a secondary text editor will show:
storage media 1. Garbage values
2. named location on a primary 2. ASCII values
storage media 3. Binary character
3. named location on on both primary 4. Unicodes
and secondary storage media 60. We separate values in Text file by
4. None of the above using
53. How many types of files are there 1. (\n)
in python? 2. ( , )
1. 1 3. (\t)
2. 2 4. both 2 and 3
3. 3
4. 4
54. The files that consists of human
readable characters
1. Binary file
2. Text file
3. Both 1 and 2
4. None of the above
55. File that require specific programs
to access its contents.
1. Unicode file
2. Text file
3. Binary file
4. ACII file
56. Files that represent ASCII values of
characters.
1. Unicode file
2. Text file
3. Binary file
4. ACII file
57. Each line of a text file is
terminated by a special character,
called?
1. End of file
2. End of byte
3. End of line
4. All the above
58. Teh default EOL character in
Python is:
1. /n
2. \n

You might also like