多个分隔符分割字符串
一种类型的分隔符进行分割:
a = 'name-age-hobby'
b1 = a.split('-')
b2 = a.split('-',1)
b3 = a.rsplit('-',1)
print(b1) >>>['name', 'age', 'hobby']
print(b2) >>>['name', 'age-hobby']
print(b3) >>>['name-age', 'hobby']
多种类型的分隔符进行分割:
import re
a = 'name-age-work/habby?salary'
b= re.split('[-/?]',a)
print(b) >>>['name', 'age', 'work', 'habby', 'salary']