Page 277 - Computer Science Class 11 Without Functions
P. 277

3.  When a string is enclosed between  single quotes, a double quote mark may be included as part of the string.  _________
               4.  Strings in Python are mutable.                                                          _________
               5.  The character sequence \n is counted as a single character while computing the length of the string.    _________
               6.  If, s == 'abc' yields True, the expression s[0:10] will yield an error.                 _________
               7.  String method split() always returns a tuple of length three.                           _________
            C.  Fill in the blanks.
               1.  Python built-in type _____________ enables us to deal with the strings in a Python program.
               2.  To include a single quote (') in a string enclosed in single quotes, it should be preceded by a _________ character.
               3.  Position of a character in a string is called its __________.
               4.  The built-in function that returns the number of characters in a string is __________.
               5.  Any value can be transformed to a string using the ___________ function.
               6.  A  subsequence of characters of a string is called a _____________.
               7.  For any string s, s[:n] + s[n:] always yields  ____________, irrespective of the value of n.
               8.  The ___________ method returns a string which has the first letter of every word of the original string converted to uppercase.
            D. Answer the following questions:
               1.  Consider the following assignment statement:
                  >>> tag = 'UnCover and COVer'
                  Using  slicing, write an expression that would yield the substring 'COVer' from the string  tag.
             Ans:  Any of the following expressions may be used to achieve this.

                  tag[-5:], tag[12:17], tag[12:]
               2.  Which arithmetic operator is used to concatenate two strings?
             Ans:  + operator

               3.  What will be the output produced on the execution of the following code?
                  message = 'Gr843?*$'


                  length = len(message)
                  newStr = ''
                  for i in range(0, length):
                      if message[i].islower():
                          newStr = newStr + message[i].upper()
                      elif message[i].isdigit():
                          newStr = eval(message[i])
                          newStr = str(newStr)
                      else:
                          newStr = newStr + '#'

                  print(newStr)
             Ans:  3###

               4.  What will be the output produced on execution of the following code?
                  message = 'Hello123Hello?*$'
                  length = len(message)
                  newStr = ''
                  for i in range(0, length):
                      if message[i].islower():


                                                                                                       Strings   275
   272   273   274   275   276   277   278   279   280   281   282