center:用来在两边填充字符,让字符串居中
'the middle is sssssss'.center(20)
' The middle is lx '
strip:删除开头结尾空白字符
' The middle is lx '.strip()
'The middle is lx'
names=['lx','dt','xx']
>> name='lx '
>> if name in names: print('this is true')
...
>> if name.strip() in names: print('this is true')
...
this is true
find:在字符串中查找子串,返回第一次出现子串的索引
'The middle is lx'.find('lx')
14
join:合并字符串序列元素
seq=['1','2','3','4','5']
>> sep.join(seq)
'1+2+3+4+5‘
split:拆分字符串序列
seq='1+2+3+4+5+6'
>> seq().split('+')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>> seq.split('+')
['1', '2', '3', '4', '5', '6']
>> sep=seq.split('+')
>> sep
['1', '2', '3', '4', '5', '6']
lower:返回字符串小写版本
'TTT111'.lower()
'ttt111'
replace:将指定字符串替换为另一个字符串。并返回替换后结果
this is a test'.replace('is','are')
'thare are a test'
>> 'this is a test'.replace('is','ere')
'there ere a test'