19.partition
语法:str.partition(sep) \\\\\把字符串以指定字符分割
解释:在字符串中搜索sep,并返回元组(sep前面的部分,sep,sep后面的部分)
>>> x = 'apple'
>>> x.partition('pl')
('ap', 'pl', 'e')
19.2 rpartition
语法:str.repartition(sep)
解释:在字符串中从右边开始搜索sep,并返回元组(sep前面的部分,sep,sep后面的部分)
>>> x = 'with a moo-moo here, and a moo-moo there'
>>> x.partition('moo')
('with a ', 'moo', '-moo here, and a moo-moo there')
>>> x.rpartition('moo')
('with a moo-moo here, and a moo-', 'moo', ' there')
20.join
语法:str.join(sequence) \\\\\\根据指定字符串拼接数据
解释:将字符串,元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串。所合并的序列元素必须都是字符串。
>>> x = [1,2,3,4,5]
>>> sep ='/'
>>> sep.join(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, int found
>>> x = ['a', 'b' ,'c']
>>> sep.join(x)
'a/b/c'
>>> '/'.join(('a','b','c'))
'a/b/c'
>>> '/'.join({'name':'lokp','age':18})
'name/age'