Page 148 - PYTHON-12
P. 148

OBJECTIVE TYPE QUESTIONS
                1.  Fill in the blanks.
                   (a)  ..................... format is a text format, accessible to all applications across several platforms.
                   (b)  ..................... method is used for random access of data in a CSV file.
                   (c)  ..................... method of pickle module is used to write an object into binary file.
                   (d)  ..................... method of pickle module is used to read data from a binary file.
                   (e)  ..................... statement is given for importing csv module into your program.
                    (f)  ..................... is a string method that joins all values of each row with comma separator in CSV.
                   (g)  ..................... object contains the number of the current line in a CSV file.
                   (h)  To end all the file contents in form of a list, ..................... method is used.
                    (i)  To read all the file contents, ....................., method may be used.
                    (j)  To force Python to write the contents of file buffer on to storage file, ..................... method may be
                       used.
                  Answers:  (a)  CSV                     (b)  seek()                  (c)  dump()
                            (d)  load()                  (e)  import csv              (f)  join()
                            (g)  line_num                (h)  readlines()             (i)  writelines()
                             (j)  flush()
                2.  State whether the following statements are True or False.
                   (a)  CSV module can handle CSV files correctly regardless of the operating system on which the files
                       were created.
                   (b)  CSV module gets automatically imported into your program for reading a CSV file.
                   (c)  The type of operation that can be performed on a file depends upon the file mode in which it is opened.
                   (d)  Functions readline() and readlines() are essentially the same.
                   (e)  Every record in a CSV file is stored in reader object in the form of a list.
                    (f)  writerow() method allows us to write a list of fields to the CSV file.
                   (g)  Comma is the default delimiter for a CSV file.
                   (h)  tell() method of Python tells us the current position within the file.
                    (i)  The offset argument to seek() method indicates the number of bytes to be moved.
                    (j)  If the offset value is set to 2, beginning of the file would be taken as seek position.
                  Answers:  (a)  True     (b)  False     (c)  True     (d)  False     (e)  True     (f)  True
                            (g)  True     (h)  True      (i)  True      (j)  False

                3.  Multiple Choice Questions (MCQs)
                   (a)  Which of the following is not a valid mode to open a file?
                       (i)  ab               (ii)  rw              (iii)  r+              (iv)  w+
                   (b)  Which statement is used to change the file position to an offset value from the start?
                       (i)  fp.seek(offset, 0)                      (ii)  fp.seek(offset, 1)
                      (iii)  fp.seek(offset, 2)                    (iv)  None of the above
                   (c)  The difference between r+ and w+ modes is expressed as?
                       (i)  No difference
                       (ii)  In r+ mode, the pointer is initially placed at the beginning of the file and the pointer is at the
                           end for w+
                      (iii)  In w+ mode, the pointer is initially placed at the beginning of the file and the pointer is at the
                           end for r+
                      (iv)  Depends on the operating system
                   (d)  What does CSV stand for?
                       (i)  Cursor Separated Variables              (ii)  Comma Separated Values
                       (iii)  Cursor Separated Values              (iv)  Cursor Separated Version
                   (e)  Which module is used for working with CSV files in Python?                                Python Libraries
                       (i)  random           (ii)  statistics      (iii)  csv             (iv)  math
                                                                                                            4.19
   143   144   145   146   147   148   149   150   151   152   153