tuples/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 09 Nov 2010 16:51:00 +0530
changeset 425 c943cdbee397
parent 232 da873a5ac918
permissions -rw-r--r--
Cleaned up tuples LO.

Objective Questions
-------------------

 1. Define a tuple containing two values. The first being integer 4 and second
    is a float 2.5

   Answer: (4, 2.5)

 2. If ``a = (5, "Hello", 3.2)``. what is the value of a[2]

   Answer: 3.2

 3. If ``a = 5,`` then what is the type of a

   a. int
   #. float
   #. tuple
   #. string

   Answer: tuple

 4. if ``a = (2, 3)``. What does ``a[0], a[1] = (3, 4)`` produce

   Answer: Error

 5. If ``a = ([2, 3], 4, 5)``. What is the value of ``a`` after doing
    ``a[0].append(6)``

    a. ([2, 3, 6], 4, 5)
    #. Raises an error
    #. ([2, 3], 4, 5)
    #. [2, 3, 4, 5, 6]

    Answer: ([2, 3, 6], 4, 5)

 6. What does the following code produce::

      a = 5
      b = "Hello"
      a, b = b, a
      print a
      print b

    Answer::

      Hello
      5

 7. ``a = ("hello", "world", 5, 6, 8)``. What is the value of a[1:4]

    Answer: ("world", 5, 6)

 8. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[1::3]

    Answer: (2, 5, 8)

 9. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[-3::-1]

    Answer: (6, 5, 4, 3, 2, 1)

 10. What is the output of the code block below::

       a = "hello", "bye", "welcome", "goodnight"
       type(a)

    Answer: <type 'tuple'>