Slicing a string split()

Python split() slices the string by specifying the delimiter. If the parameter num has a specified value, only num substrings are separated.
str.split(str="", num=string.count(str))
Parameter
str– delimiter, the default is all empty characters, including spaces, newlines (\n), Tabs (\t), etc.
num– Number of splits.

#!/usr/bin/python

str = "Line1-abcdef \nLine2-abc \nLine4-abcd";
print str.split( );
print str.split(' ', 1 );
# 以上实例输出结果如下:
['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
['Line1-abcdef', '\nLine2-abc \nLine4-abcd']

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325453451&siteId=291194637