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

So, a null string has also been included in the list. The following example is even more interesting,

         >>> 'Awesome!!!, oh! my God!'.split('!')
              ['Awesome', '', '', ', oh', ' my God', '']
        Next, let us split a multi-line string, using the default delimiter whitespace.

         >>> address =   '''Ram Niwas Yadav,
                24/7, Ahmedpur, Vidisha,
                PIN 464001'''
         >>> address.split()
              ['Ram', 'Niwas', 'Yadav,', '24/7,', 'Ahmedpur,', 'Vidisha,', 'PIN', '464001']
        ●  s.partitition(delimit):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, as illustrated below:

         >>> txt = 'Amey my friend, Amey my guide'
         >>> txt.partition(',')
              ('Amey my friend', ',', ' Amey my guide')

               split(delimit): Returns a list of substrings, separated by the given delimiter: delimit.
               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.
               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.


        ●  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.









         268   Touchpad Computer Science-XI
   265   266   267   268   269   270   271   272   273   274   275