getting-started-strings/questions.rst
changeset 313 b9b7bfce773e
equal deleted inserted replaced
312:8cb703eee88d 313:b9b7bfce773e
       
     1 Objective Questions
       
     2 -------------------
       
     3 
       
     4 .. A mininum of 8 questions here (along with answers)
       
     5 
       
     6 1. List the type of quotes that can be used to define strings. 
       
     7  
       
     8    Answer: 'single quotes', "double quotes", 
       
     9            '''triple single quotes'''
       
    10            """triple double quotes"""
       
    11    
       
    12 #. Given the strings ``s`` and ``S``, ``s='Hello World'`` and
       
    13    ``S="Hello World``. s and S are different strings. True or False?
       
    14 
       
    15 #. What is the output of::
       
    16    
       
    17      s = 'It's all here'
       
    18 
       
    19    Answer: ``SyntaxError``
       
    20 
       
    21 #. Write code to assign s, the string ``' is called the apostrophe``
       
    22 
       
    23    Answer: ``s = "`is called the apostrophe"``
       
    24 
       
    25 #. Given strings s and t, ``s = "Hello"`` and ``t = "World"``. What is
       
    26    the output of s + t?
       
    27 
       
    28    Answer: HelloWorld
       
    29 
       
    30 #. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an
       
    31    integer r, ``r = 2``. What is the output of s * r + s * t?
       
    32 
       
    33    Answer: HelloHelloWorldWorld
       
    34 
       
    35 #. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an
       
    36    integer r, ``r = 2``. What is the output of s * 'r' ? 
       
    37 
       
    38    Answer: TypeError - can't multiply a sequence by non-int
       
    39 
       
    40 #. Given the string ``s = "Hello"``, we wish to change it to
       
    41    ``hello``. what is the result of::
       
    42    
       
    43      s[0] = 'h'
       
    44 
       
    45    Answer: TypeError - 'str' object does not support item assignment. 
       
    46 
       
    47 #. Given the string ``s = "Hello"``, we wish to change it to
       
    48    ``hello``. what is the result of::
       
    49    
       
    50      s = "hello"
       
    51 
       
    52    Answer: s is changed to "hello"
       
    53 
       
    54 #. Which type of string can be written in multiple lines, with line
       
    55    breaks. (Note: more than one answer may be correct.)
       
    56 
       
    57    #. triple double quoted strings
       
    58    #. single quoted strings
       
    59    #. double quoted strings
       
    60    #. triple single quoted strings
       
    61 
       
    62    Answer: triple double quoted strings and triple single quoted strings
       
    63 
       
    64 Larger Questions
       
    65 ----------------
       
    66 
       
    67 .. A minimum of 2 questions here (along with answers)
       
    68 
       
    69 1. Given the string s, ``s = F.R.I.E.N.D.S``, obtain the string
       
    70    "FRIENDS". 
       
    71 
       
    72    Answer::
       
    73    
       
    74      s = s[0] + s[2] + s[4] + s[6] + s[8] + s[10] + s[12] 
       
    75 
       
    76 2. Assign the string ``Today's Quote: "Don't believe in any quote,
       
    77    including this."`` to the variable ``quote``. 
       
    78 
       
    79    Answer: 
       
    80    quote = """Today's Quote: "Don't believe in any quote, including this."""