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

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 Exercises


              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-7:
                 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','#')
                 9.  Which of the following calls to str methods will yield a list of all words from the string info?
                    a.  info.list()          b. info.partition()  c. info.convert()       d. info.split()
                10.  Which of the following built-in str methods will always return a tuple comprising three elements?
                    a.  list()               b. find()              c. partition()        d. split()

               354   Touchpad Computer Science (Ver. 2.0)-XI
   363   364   365   366   367   368   369   370   371   372   373