getting-started-strings/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Fri, 05 Nov 2010 21:17:10 +0530
changeset 379 4b3c0d8fffe2
parent 313 b9b7bfce773e
permissions -rw-r--r--
Changes to getting started with files based on review.

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

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

1. List the type of quotes that can be used to define strings. 
 
   Answer: 'single quotes', "double quotes", 
           '''triple single quotes'''
           """triple double quotes"""
   
#. Given the strings ``s`` and ``S``, ``s='Hello World'`` and
   ``S="Hello World``. s and S are different strings. True or False?

#. What is the output of::
   
     s = 'It's all here'

   Answer: ``SyntaxError``

#. Write code to assign s, the string ``' is called the apostrophe``

   Answer: ``s = "`is called the apostrophe"``

#. Given strings s and t, ``s = "Hello"`` and ``t = "World"``. What is
   the output of s + t?

   Answer: HelloWorld

#. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an
   integer r, ``r = 2``. What is the output of s * r + s * t?

   Answer: HelloHelloWorldWorld

#. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an
   integer r, ``r = 2``. What is the output of s * 'r' ? 

   Answer: TypeError - can't multiply a sequence by non-int

#. Given the string ``s = "Hello"``, we wish to change it to
   ``hello``. what is the result of::
   
     s[0] = 'h'

   Answer: TypeError - 'str' object does not support item assignment. 

#. Given the string ``s = "Hello"``, we wish to change it to
   ``hello``. what is the result of::
   
     s = "hello"

   Answer: s is changed to "hello"

#. Which type of string can be written in multiple lines, with line
   breaks. (Note: more than one answer may be correct.)

   #. triple double quoted strings
   #. single quoted strings
   #. double quoted strings
   #. triple single quoted strings

   Answer: triple double quoted strings and triple single quoted strings

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

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

1. Given the string s, ``s = F.R.I.E.N.D.S``, obtain the string
   "FRIENDS". 

   Answer::
   
     s = s[0] + s[2] + s[4] + s[6] + s[8] + s[10] + s[12] 

2. Assign the string ``Today's Quote: "Don't believe in any quote,
   including this."`` to the variable ``quote``. 

   Answer: 
   quote = """Today's Quote: "Don't believe in any quote, including this."""