Page 311 - Computer Science Class 11 Without Functions
P. 311

9.  If the variable s refers to the list [1, 2, 3], then s.extend((4, 5, 6)) returns None.   ________

              10.  [1, 2, 3, 4] is [1, 2] + [3, 4] yields True.                                             ________
            C.  Fill in the blanks.
               1.  The ____________ function is used to add an element at the end of an existing list.
               2.  While a list is _________ (mutable/ immutable), a tuple is  ________.
               3.  The _________ function returns  a list comprising elements of a tuple in sorted order.
               4.  The method mean is included in the module __________.
               5.  The expression [].pop() will yield __________.
              6. [2, 6, 3]*0 will yields ________.
              7. [1, 2].extend([4, 5, 6]) yields _______.
              8. s = []; s.append((1, 2, 3)); print(s) will print __________.
              9. s = []; s.extend((1, 2, 3)); print(s) will print __________.
              10. [1, 2, 3, 4] == [1, 2] + [3, 4] will yield _________.
              11. [1, 2, 3, 4][2:2] will yield _______.
            D.  Answer the following questions:
               1.  What  is  the  difference  between  mutable  and  immutable  objects?  Give  an  example  of  an  object  of  each  of  these
                  types.
             Ans:  An object that can be modified is called mutable. Example: [1, 2, 3].
                  An object that cannot be modified is called immutable. Example: (1, 2, 3).
               2.  Give two examples of mutable types.

             Ans:  list, and set.
               3.  Give four examples of immmutable types.

             Ans:  int, float, tuple, str.
               4.  What is the index of the first element of a tuple?
             Ans:  0
               5.  What is the difference between a list and a tuple?

             Ans:                       List                                       Tuples
                   A list is mutable.                            A tuple is immutable.
                   Lists are enclosed in brackets[] and their elements and  Tuples are enclosed in parethesis() and can not be
                   size can be changed.                          updated.
                   Example:                                      Example:
                   L = [10,11,12,13]                             S = ("Orange","education")
                                                                 or

                                                                 S = ("orange","education")
               6.  The function print(x) may be used to display either a list (x) or a  tuple (x) . Will the output be same or different in the
                  two case? Justify  your answer. Give the output that will be produced on execution of the following code?
                      print([1, 2, 3])
                      print((2, 2, 3))
             Ans.   Elements of a list are separated by commas and enclosed in square parentheses []. Elements of a tuple are separated by
                  commas and enclosed in round parentheses.

                  [1, 2, 3]
                  (1, 2, 3)




                                                                                                Lists and Tuples  309
   306   307   308   309   310   311   312   313   314   315   316