Python?split()?通過指定分隔符對字符串進(jìn)行切片,如果參數(shù) num 有指定值,則分隔 num+1 個子字符串
語法
str.split(str="", num=string.count(str)).
參數(shù)
str -- 分隔符,默認(rèn)為所有的空字符,包括空格、換行(\n)、制表符(\t)等。
num -- 分割次數(shù)。默認(rèn)為 -1, 即分隔所有。
返回值
返回分割后的字符串列表。
實(shí)例
ten_things = "apples oranges crows telephone light sugar"
stuff = ten_things.split(' ', len(ten_things) )
print(stuff)
打?。篬'apples', 'oranges', 'crows', 'telephone', 'light', 'sugar']