tuples.rst
changeset 222 d5249a528cae
parent 153 22521a1d6841
equal deleted inserted replaced
221:7cd975ff5f0d 222:d5249a528cae
   146  
   146  
   147 .. Author              : Nishanth
   147 .. Author              : Nishanth
   148    Internal Reviewer 1 : 
   148    Internal Reviewer 1 : 
   149    Internal Reviewer 2 : 
   149    Internal Reviewer 2 : 
   150    External Reviewer   :
   150    External Reviewer   :
       
   151 
       
   152 Questions
       
   153 =========
       
   154 
       
   155  1. Define a tuple containing two values. The first being integer 4 and second
       
   156     is a float 2.5
       
   157 
       
   158    Answer: (4, 2.5)
       
   159 
       
   160  2. If ``a = (5, "Hello", 3.2)``. what is the value of a[2]
       
   161 
       
   162    Answer: 3.2
       
   163 
       
   164  3. If ``a = 5,`` then what is the type of a
       
   165 
       
   166    a. int
       
   167    #. float
       
   168    #. tuple
       
   169    #. string
       
   170 
       
   171    Answer: tuple
       
   172 
       
   173  4. if ``a = (2, 3)``. What does ``a[0], a[1] = (3, 4)`` produce
       
   174 
       
   175    Answer: Error
       
   176 
       
   177  5. If ``a = ([2, 3], 4, 5)``. What is the value of ``a`` after doing
       
   178     ``a[0].append(6)``
       
   179 
       
   180     a. ([2, 3, 6], 4, 5)
       
   181     #. Raises an error
       
   182     #. ([2, 3], 4, 5)
       
   183     #. [2, 3, 4, 5, 6]
       
   184 
       
   185     Answer: ([2, 3, 6], 4, 5)
       
   186 
       
   187  6. What does the following code produce::
       
   188 
       
   189       a = 5
       
   190       b = "Hello"
       
   191       a, b = b, a
       
   192       print a
       
   193       print b
       
   194 
       
   195     Answer: Hello
       
   196             5
       
   197 
       
   198  7. ``a = ("hello", "world", 5, 6, 8)``. What is the value of a[1:4]
       
   199 
       
   200     Answer: ("world", 5, 6)
       
   201 
       
   202  8. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[1::3]
       
   203 
       
   204     Answer: (2, 5, 8)
       
   205 
       
   206