Page 325 - Computer Science Class 11 With Functions
P. 325
(viii) quote.isdigit()
(ix) quote.isspace()
(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')
Strings 323

