python的split函數(shù)作用 python字符串分割split()函數(shù)中中英文逗號分割?
python字符串分割split()函數(shù)中中英文逗號分割?在Python中用split()方法分割字符串的使用介紹 這篇文章主要介紹了在Python中用split()方法分割字符串的使用介紹,是Pyt
python字符串分割split()函數(shù)中中英文逗號分割?
在Python中用split()方法分割字符串的使用介紹 這篇文章主要介紹了在Python中用split()方法分割字符串的使用介紹,是Python入門中的基礎(chǔ)知識,需要的朋友可以參考下 split()方法返回的字符串中的所有單詞的列表,使用str作為分隔符(如果在未指定的所有空格分割),可選擇限當(dāng)前分割為數(shù)量num。 語法 以下是split()方法的語法: str.split(str="", num=string.count(str)). 參數(shù) str -- 這是任何分隔符,默認(rèn)情況下是空格。 num -- 這是要分割的行數(shù)。 返回值 此方法返回行列表。 例子 下面的示例演示了split()方法的使用。 #!/usr/bin/python str="Line1-abcdef nLine2-abc nLine4-abcd" printstr.split( ) printstr.split(" ",1) 當(dāng)我們運行上面的程序,它會產(chǎn)生以下結(jié)果: ["Line1-abcdef","Line2-abc","Line4-abcd"] ["Line1-abcdef","nLine2-abc nLine4-abcd"]