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

s.startswith(subStr): Tests whether the string starts with the string subStr, passed as a parameter.
                     s.endswith(subStr): Tests whether the string ends with the suffix subStr, passed as a parameter.
                     s.find(subStr): Returns the index of the first occurrence of the string passed as an argument.
                     s.rfind(): Returns the index of the last occurrence of a substring in the given string.
                     s.index(subStr): Returns the index of the first occurrence of the substring passed as an argument.

                     s.replace(old, new): Returns a string where all occurrences of the old string are replaced by the
                     new string.
                     s.split(delimit): Returns a list of substrings, separated by the given delimiter: delimit
                     s.partition(delimit): Splits the string into three parts, part of the string before delimiter, delimiter
                     itself, and part of the string after delimiter.
                     s.join(list): Joins the strings in the given list (comma-separated sequence of values provided within
                     square brackets) together using the string as the delimiter.








                                                  Solved Exercise


            A.  Multiple Choice Questions
               1.  To which element of the string does the index -1 refer?
                  a.  First                b. Second              c. Last               d. Second last

               2.  Which of the following operators cannot be used with strings?
                  a.  +                    b. *                   c. in                 d. -
               3.  Which of the following methods is used to count the number of characters in a string?
                  a.  count()              b. len()               c. find()             d. index()
                  Consider the following assignment statement and answer Questions 4-6:

                  message = "I love my India"
               4.  Which of the following slices will yield the last five characters of the string message?
                  a.  message[-5:]         b. message[5:]         c. message[:-5]       d. message[:5]
               5.  Which of the following slices will yield the first three characters of the string message?
                  a.  message[-3:]         b. message[3:]         c. message[:-3]       d. message[:3]
               6.  Which of the following slices will yield 'my In'  from the string message?
                  a.  message[-5:-7:-1]  b. message[7:11]         c. message[-8:-1:-1] d. message[7:12]
               7.  Which of the following method calls will yield a string that substitutes all lowercase letters with the corresponding uppercase
                  letters?
                  a.  message.upper()      b. message.toupper() c. message.isupper() d. message.UPPER()
                  Consider the following assignment statement to answer Questions 8-10:
                  info = "Assemble in ground"
               8.  Which of the following calls to str methods will yield a string that  replaces each occurrence of 's'  with   '#'?
                  a. info.find('s','#')
                  b. info.replace('s','#')
                  c. info.replace('#','s')
                  d. info.index('s','#')



                                                                                                       Strings   273
   270   271   272   273   274   275   276   277   278   279   280