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

●  s.join(list): Joins the strings in the given list (comma-separated sequence of values provided within square
                   brackets) together using the string s as the delimiter. For example,
                  >>> '>>'.join(['a', 'b', 'c', 'd'])
                      'a>>b>>c>>d'
                 The strings in the list ['a', 'b', 'c', 'd'] are joined together using '>>' as the delimiter.
                 Next, let us consider an example that uses a space as the delimiter to print the concatenated string that spreads over
                 multiple lines.

                  >>>  ' '.join(['Hello', '\tHow', 'are', 'you?\n', 'I', 'am', 'fine.\n', 'How', 'are', 'you?'])
                      'Hello \tHow are you?\n I am fine.\n How are you?'

                  >>>  print(' '.join(['Hello', '\tHow', 'are', 'you?\n', 'I', 'am', 'fine.\n', 'How', 'are',
                      'you?']))
                      Hello       How are you?
                      I am fine.
                      How are you?



                         Write the names of the functions that will be used to perform the following tasks:
                           (i)  To convert a string to uppercase.
                           (ii)  To find the length of a string.
                          (iii)  To check whether a string consists of digit(s).
                          (iv)  To return a list of words from the string.
                           (v)  To display the index of a character in a string.
                          (vi)  To replace the character in a string with a new character.
                          (vii)  To return a string with the first character of each word capitalized.
                           (viii)  To remove the leading spaces from a string.



                 The built-in functions for string manipulations are summarized in the following table:
                                               Table 12.1: Built-in functions for string manipulations

                          Method                       Description                              Example

                 len(string)               Returns the length of a string      >>> string_s1= 'Touchpad
                                                                               Computer Science'
                                                                               >>> len(string_s1)

                                                                               25
                 str.count(string)         Returns the number of occurrences of  >>> string_s1.count('c')
                                           the string, passed as the argument to  3
                                           the method count().

                 str.lower()               Returns the lowercase version of the  >>> string_s1.lower()
                                           string.                             touchpad computer science

                 str.upper()               Returns the uppercase version of the  >>> string_s1.upper()
                                           string.                             TOUCHPAD COMPUTER SCIENCE

                 str.title()               Returns  a  string  that  has  the  first  >>> string_s1.title()
                                           letter  of  every  word  of  the  original  Touchpad Computer Science
                                           string  converted  to  uppercase,  while
                                           remaining  letters  are  converted  to
                                           lowercase.



                                                                                                            Strings   347
   356   357   358   359   360   361   362   363   364   365   366