Python版本:3.7.4
split(pattern, string, maxsplit=0, flags=0)
原文
Split the source string by the occurrences of the pattern,from re import split
a = split(',', 'aa,bb')
print(a)
['aa', 'bb']
from re import split
a = split(',', 'aa,bb,cc', 1)
print(a)
['aa', 'bb,cc']
from re import split
a = split(',', ',aa,,bb,')
print(a)
['', 'aa', '', 'bb', '']
from re import split
a = split('(,)', 'aa,')
print(a)
['aa', ',', '']
from re import split
a = split('aa(bb(cc))', 'ZaabbccZ')
print(a)
['Z', 'bbcc', 'cc', 'Z']
from re import split
a = split(',|(;)', 'aa,bb;cc')
print(a)
['aa', None, 'bb', ';', 'cc']
from re import split
a = [i for i in split(',|(;)', ',aa,;bb,')if i]
print(a)
['aa', ';', 'bb']