语法
以下是split()方法的语法:
str.split(str=, num=string.count(str)).
参数
str -- 这是任何分隔符,默认情况下是空格。 num -- 这是要分割的行数。返回值
此方法返回行列表。
例子
下面的示例演示了split()方法的使用。
#!/usr/bin/pythonstr = 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']
