You are on page 1of 4

OBJECTIVE TYPE QUESTIONS=

1. Fill in the blanks.

(a) ... in Python are interpreted as a sequence or stream of bytes stored on some storn
media.
(b) The..
(b) The. function creates a file object used to call other support methods associated witk
(c) Files in Python can be opened in one of the three modes.
and....
(d) The.. method writes a
..
list of strings to a file.
(e) The . . . . method of a file object flushes any unwritten information and closes the file obje=
(f) The name of the current working directory can be determined
using ... method. . .

8) The.. method is used to rename the file or folder.


h) The ... method is used to remove/delete a file.
...

(i) A... . file is a series of 1's and 0's, treated as raw data and read byte-by-byte.
he.statement automatically closes the file afterthe processing on the file gets over.
(k) The read() function reads data from the . . . of a file.
two main methods called.***ossose. dna....
()The pickle module produces for writing a
reading operations. and
from the file t i l l . .
(m) The readlines() returns a list of lines
the file.
(n) The. method reads 'n' characters from
from buffer to file.
(o) functionis used to force transfer of data
(p) . format is a text format accessible to all applications across several nla
method is used for random access of data in a CSV file. tforms.
() . method of pickle module is used to write an object into binary file.
(S) . method of pickle module is used to read data from a binary file.
(t) . statement is given for importing csV module into your program.
(u) . i s a string method that joins the string with a string separator.
(v)****s********
.object contains the number ofthe current line in a CSV file.
(w) To read all the file contents in the form of a list, . method is used.
(x) To write contents of list, tuple and sequence data type,
. method may be used
(v) To force Python to write the contents of file buffer on to storage file,
used.
*******.****
method maybe
(z) When we work with file, .
open it.
ssesses*.. .. area is automatically associated with the file
when we
2. State whether the following statements are True
or False.
(a) An absolute path always begins with the root
folder.
(b) It is not necessary to always create the
file in the same default
installed. folder where Python has been
(c) In
binary file, there is no delimiter for a
line.
(d) A binary file stores
information in ASCll or Unicode
(e) readline() reads the entire file characters.
at a time.
(6) A closel) function breaks the
link of the file
e) When you open a file in read object and the file on the disk.
FileNotFound error. mode, the given file must
exist in the folder;
otherwise Python wi
(h) The default file
open mode is write mode.
) Opening a file in
append mode erases the
0) A file mode defines
the type of previous data.
(k) stream is defined as
A operations that is to be
() readlines() function
a
sequence of characters. performed on the frile.
returns a list of
(m) Data maintained
inside
strings, each separated by "\n".
the file is
(n)with statement termed as
ensures that all the "persistent" (permanent in nature) a.

(o)
automatically. resources allocated to the file
aae get deallocat

CSV module can handle CSV files


objects B
were created.
correctly regardless of the operating which the t
(p) csv module gets syste
automatically
operation that canimported
(q) The type of into your
opened. be program for reading a CSV
(o) performed on a file T hichi

Functions readline() depends upon the file mo


s)Every record in a CSVand readlines() are
(t) writerow() file is stored essentially the same.
in reader
(u) Comma is the method allows us to write object in the form of a list.
a list
default of fields to the CSV
() tell()
method of Pythondelimiter for a CSV file. file.
(w) The offset tells us the
4.44 (x) If the offset argument
to current
value is seek() method indicates
position within the file.
set to 2,
beginning of the filethewould
number
umber of bytes to be moved.
bytes
be taken as seek sition.
Multiple Choice Questions (McQs)

(a) To open a :\test.txt for reading,


file c:\t we should
give the statement:
filel= open ("c:\ test.txt", "r")
t) filel = open " c : \ \ t e s t . t x t " , "")

i filel =
open (file =
"C:\ test.txt", "r")
tiv filel =
open (file =
"c:\\s test.txt", "r")
lTo open a file c:\ test.txt for writing, we should use the statement:
) f o b j = open ("c: \ t e s t . t x t " , "w")

(i) fobj = open ( " c : \ \ t e s t . t x t " , "w")

ii) fobj =open (file =


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

(c) To open a file c:\ test.txt for appending data, we can give the statement:
() fobj = open ( " c : \ \ t e s t . t x t " , "a")

(ii) fobj = open ( " c : \ \ t e s t . t x t " , "rw")

(ii) fobj = open ( f i l e = "c:\test.txt", "w")

(iv) fobj = open ( f i l e = " c : \ t e s t . t x t " , "w")

(d) Which of the following statements is/are true?


) When you open a file for reading, if the file does not exist, an error occurs.
(i) when you open a file for writing, if the file does not exist, a new file is created.
(ii) When you open a file for writing, if the file exists, the existing file is overwritten with the new
file.
(iv) All of the above.
(e) To read two characters from a file object fobj, the command should be:
i) fobj.read (2) (ii) fobj.read ()
(i) fobj.readline () (iv) fobj.readlines ()
() To read the entire contents of the file as a string from a file object fobj, the command should be:
() fobj.read (2) i) fobj.read ()
(ii) fobj. readline () (iv) fobj.readlines ()
e) 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)
i) True (ii) False (ii) Nonee (iv) Error
(h) To read the next line of the file from a file object fobj, we use:
i) fobj. read (2) (i) fobj.read ()
(ii) fobj.readline () (iv) fobj.readlines ()
i) To read the remaining lines of the file from a file object fobj, we use:
() fobj.read (2) () fobj.read ()
(ii) fobj.readline () (iv) fobj.readlines ()
) The readl ines () method returns:
() String (i) A list of integers
(ii) A list of single characters (iv) A list of lines

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


(i) math (i) flush (ii) pickle (iv) unpickle
which ofthe following functions is used to wrte data in the binary mode?
(i)write (i) output (ii) dump (iv) send 4.45
stream(s) in file?
(m) Which is/are the basic 1/0 (input-output)
(i) Standard Input (ii) Standard Output
(ii) Standard Errors (iv) All of the abovve
(n) Which of the following is the correct syntax of file object 'fobj' to write seaue.
uence data type use
writelines() function?
(i) file.writelines (sequence) (i) fobj.writelines()
(in) fobj.writelines (sequence) (iv) fobj.writeline ()
(o) In file handling, what do the terms "" and "a" stand for?
(i) read, append (ii) append, read
(ii) write, append (iv) None of the above
(P) Which of the following is not a valid mode to open a file?
(i) ab ii) rw (i) r+ (iv) w+
(q) Which statement is used to change the file position to an offset value from
the start?
(i) fp.seek (offset, 0) (i) fp.seek (offset, 1)
(ii) fp. seek (offset, 2) (iv) None of the above
()The difference between r+ and w+ modes is as? expressed
(i) No difference
(ii) In r+ mode, the pointer is initially placed at the
end for w+ beginning of the file and the pointer is at the
(ii) In w+ mode, the
pointer is initially placed at the beginning of the file and the
end for r+ pointer is at the
(iv) Depends the operating system
on
(s) What does CSV stand for?
(i) Cursor Separated Variables
(ii) Cursor (ii) Comma Separated Values
Separated Values (iv) Cursor Separated Version
(t) Which module is used for
working with CSV files in Python?
i) random (i) statistics
(u) Which of the following modes is used (ii) csv (iv) math
for both
writing and reading from
(i) wb+ (i) w
a binary file
(v) Which statement is used to retrieve (ii) wb (iv) w+
the current
(i) fp.seek() position within the file?
(i) fp.tell()
(w) What happens if no arguments are (ii) fp.loc (iv) fp.pos
() file position is set to the start ofpassed the
to
seek() method?
file (1) file position is set to the end of file
(iii) file position remains
unchanged (iv) results in
(x) Which of the following modes will refer
an error
to binary data?
(i) r (ii) w
(y) Every record in a CSV file is stored in (i) (iv) b
reader object in the thod?
(i) writer() form of a list using which met
() append() (ii) reader()
(2) For storing numeric data in a (iv) list()
(i) integer, int()
text file, it needs to be converted
.. function.

(i) integer, float() into.. s5 gstr()


(iv) string, str()
(iii) string. int()

You might also like