Page 372 - Computer Science V2.0 Class 11
P. 372

(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.
                    (iii)  To get a string by removing all leading and trailing whitespace characters from a string.
                    (iv)  To check whether a string occurs as a substring of a given string.
                    (v)  To check whether the characters of a string are in lowercase.

               Ans.  (i)  isspace()
                    (ii)  upper()
                    (iii)  strip()
                    (iv)  find()
                    (v)  islower()

               358   Touchpad Computer Science (Ver. 2.0)-XI
   367   368   369   370   371   372   373   374   375   376   377