tuples/questions.rst
changeset 232 da873a5ac918
child 425 c943cdbee397
equal deleted inserted replaced
231:e78c284d644b 232:da873a5ac918
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4  1. Define a tuple containing two values. The first being integer 4 and second
       
     5     is a float 2.5
       
     6 
       
     7    Answer: (4, 2.5)
       
     8 
       
     9  2. If ``a = (5, "Hello", 3.2)``. what is the value of a[2]
       
    10 
       
    11    Answer: 3.2
       
    12 
       
    13  3. If ``a = 5,`` then what is the type of a
       
    14 
       
    15    a. int
       
    16    #. float
       
    17    #. tuple
       
    18    #. string
       
    19 
       
    20    Answer: tuple
       
    21 
       
    22  4. if ``a = (2, 3)``. What does ``a[0], a[1] = (3, 4)`` produce
       
    23 
       
    24    Answer: Error
       
    25 
       
    26  5. If ``a = ([2, 3], 4, 5)``. What is the value of ``a`` after doing
       
    27     ``a[0].append(6)``
       
    28 
       
    29     a. ([2, 3, 6], 4, 5)
       
    30     #. Raises an error
       
    31     #. ([2, 3], 4, 5)
       
    32     #. [2, 3, 4, 5, 6]
       
    33 
       
    34     Answer: ([2, 3, 6], 4, 5)
       
    35 
       
    36  6. What does the following code produce::
       
    37 
       
    38       a = 5
       
    39       b = "Hello"
       
    40       a, b = b, a
       
    41       print a
       
    42       print b
       
    43 
       
    44     Answer::
       
    45 
       
    46       Hello
       
    47       5
       
    48 
       
    49  7. ``a = ("hello", "world", 5, 6, 8)``. What is the value of a[1:4]
       
    50 
       
    51     Answer: ("world", 5, 6)
       
    52 
       
    53  8. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[1::3]
       
    54 
       
    55     Answer: (2, 5, 8)
       
    56 
       
    57  9. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[-3::-1]
       
    58 
       
    59     Answer: (6, 5, 4, 3, 2, 1)
       
    60