Latest web development tutorials

Python split () method

Python strings Python strings


Python split () by specifying a delimiter for string sections, if the parameter num value is specified, then only substrings separated num


split () method syntax:

str.split(str="", num=string.count(str)).


  • str - separator, default spaces.
  • num - the number of divisions.

return value

Returns a list of strings after division.


The following example shows the split () function to use:


str = "Line1-abcdef \nLine2-abc \nLine4-abcd";
print str.split( );
print str.split(' ', 1 );

Examples of the above output results are as follows:

['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
['Line1-abcdef', '\nLine2-abc \nLine4-abcd']

Python strings Python strings