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

(x)  quote.startswith("#Book")
                  (xi)  quote.endswith("Friends")
                  (xii)  quote.replace('e','$')
             Ans.  (i)  '#books are friends'
                  (ii)  '#BOOKS ARE FRIENDS'
                  (iii)  '#Books Are Friends'
                  (iv)  '#books are friends'
                  (v)  False
                  (vi)  False
                  (vii)  False
                  (viii) False
                  (ix)  False
                  (x)  True
                  (xi)  False
                  (xii)  '#Books ar$ fri$nds'
               7.  Consider the following string:

                  Greetings = "      Good Morning   "
                  What will  the following calls to the methods lstrip()  and rstrip() return?
                  (i)  greetings.lstrip()
                  (ii)  greetings.rstrip()
                  (iii)  greetings.strip()

             Ans.  (i)  'Good Morning   '
                  (ii)  '      Good Morning'
                  (iii)  'Good Morning'
               8.  Differentiate between partition() and split()
             Ans:  split()
                    The method split(delimit) returns a list of substrings, separated by the given delimiter.

                    The delimiter must be a string.
                    When no delimiter is specified, Python splits the string at the default delimiter, whitespace.
                    partition()
                    The  method  partition(delimit)splits  the  string  into  three  parts,  part  of  the  string  before  the  delimiter,  the
                   delimiter itself, and the part of the string after the delimiter.
                    The return type is a tuple of length 3.
               9.  Consider the following assignment statement:

                  wishes = "All the BEST"
                  What will the following calls to str methods return ?
                  (i)  wishes.split()
                  (ii)  wishes.split('t')
                  (iii) wishes.partition('h')

             Ans.  (i)  ['All', 'the', 'BEST']
                  (ii) ['All ', 'he BEST']
                  (iii) ('All t', 'h', 'e BEST')
              10.  For performing each of the following tasks, suggest the name of a suitable str method,
                  (i)  To check whether the string contains whitespace characters.
                  (ii) To get a string by replacing the lowercase alphabets  of the given string to uppercase.


                                                                                                       Strings   277
   274   275   276   277   278   279   280   281   282   283   284