Python split () method
description
Python split () by specifying a delimiter for string sections, if the parameter num value is specified, then only substrings separated num
grammar
split () method syntax:
str.split(str="", num=string.count(str)).
parameter
- str - separator, default spaces.
- num - the number of divisions.
return value
Returns a list of strings after division.
Examples
The following example shows the split () function to use:
#!/usr/bin/python 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']