9、split()
对字符串做分隔处理,最终的结果是一个列表。
s = 'string methods in python'.split()
print(s)
# ['string', 'methods', 'in', 'python']
当不指定分隔符时,默认按空格分隔。
s = 'string methods in python'.split(',')
print(s)
# ['string methods in python']
此外,还可以指定字符串的分隔次数。
s = 'string methods in python'.split(' ', maxsplit=1)
print(s)
# ['string', 'methods in python']