Python3 字符串
描述
split()通過指定分隔符對字符串進行切片,如果參數(shù)num 有指定值,則僅分隔 num 個子字符串
語法
split()方法語法:
str.split(str="", num=string.count(str)).
參數(shù)
- str -- 分隔符,默認為空格。
- num -- 分割次數(shù)。
返回值
返回分割后的字符串列表。
實例
以下實例展示了split()函數(shù)的使用方法:
#!/usr/bin/python3
str = "this is string example....wow!!!"
print (str.split( ))
print (str.split('i',1))
print (str.split('w'))
以上實例輸出結(jié)果如下:
['this', 'is', 'string', 'example....wow!!!']
['th', 's is string example....wow!!!']
['this is string example....', 'o', '!!!']
更多建議: