How to use Python split() function (split array)

describe
Python split() slits a string by specifying a delimiter, and only splits the num substring if the parameter num has a specified value
grammar
Split () method syntax:

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

parameter
STR – The delimiter, which defaults to all null characters, including Spaces, newlines (\n), tabs (\t), and so on. Num – number of splits.
The return value
Returns a list of partitioned strings.
The instance
The following example shows how to use the split() function:

#!/usr/bin/python

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

The output of the above example is as follows:

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


Read More: