tuples/questions.rst
author Nishanth <nishanth@fossee.in>
Thu, 07 Oct 2010 14:10:32 +0530
changeset 232 da873a5ac918
child 425 c943cdbee397
permissions -rw-r--r--
made the tuples.rst into new template form

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)