Python split() 通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则分隔 num+1 个子字符串
语法
str.split(str="", num=string.count(str)).
参数
str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
num -- 分割次数。默认为 -1, 即分隔所有。
返回值
返回分割后的字符串列表。
实例
ten_things = "apples oranges crows telephone light sugar"
stuff = ten_things.split(' ', len(ten_things) )
print(stuff)
打印:['apples', 'oranges', 'crows', 'telephone', 'light', 'sugar']