basic-data-type/questions.rst
author anand
Mon, 15 Nov 2010 15:23:28 +0530
changeset 510 06561ee0f6a4
parent 406 a534e9e79599
permissions -rw-r--r--
checklist OK for `writing python scripts`

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

.. A mininum of 8 questions here (along with answers)

.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
.. question.]

1. How large can an integer in Python be?

   Answer: Any Size.
   
  
#. How do you define a complex number in Python?

   Using the following notation.
   
   [Real part] + [Imaginary part] j
   example ::
   
   Answer: c= 3.2 + 4.6j


#. Look at the following piece of code ::
   
     In []: f or t 
     Out[]:True

   What can you comment about the data type of f and t ? 

#. One major diffence between tuples and lists?

   Answer: Tuples are immutable while lists are not.




#. Put the following string in a variable quotation.
   "God doesn't play dice" -Albert Einstein

   quotation='''"God doesn't play dice" -Albert Einstein'''

#. Given a tuple ::

     tup=(7,4,2,1,3,6,5,8)
     tup[-2]
  
   5

.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
.. question.]

#. What is the syntax for checking containership in Python?::

   element in sequence 
   'l' in "Hello"
    True

#. Split this string on whitespaces? ::

   string="Split this string on whitespaces?"

   string.split()
   
#. What is the answer of 5/2 and 5.0/2 . If yes , why.

    Yes, There is a difference. 
    Because one is integer division and other is float division. 

Larger Questions
----------------

.. A minimum of 2 questions here (along with answers)


1. Look at the following sequence ::

     In []:t=true
     NameError: name 'true' is not defined

   What might be the reason for error here?

   In this scenario , it seems the programmer wanted to create a
   variable t with the boolean value True with a capital T. Since no
   variable by the name true(small t) is known to the interpreter it
   gives a NameError.



#. Convert the string "I,learnt,python,through,spoken,tutorial"
   to "I,learnt through spoken tutorial"

.. #[Puneeth: comparison has not been taught, has it? does this depend
.. on any other LO?]