2.1 如何拆分拥有多个符号的字符串
import re
test_str = 'a//b/$d@p*n^l'
res = re.split('[./$@*^]+', test_str)
print(res)
2.2 将多个字符串进行拼接
little_str = ['aa', 'bb', 'cc', 'dd', 'ee']
ingrate_str = ''.join(little_str)
print(ingrate_str)
2.3 如何将字符串左右居中对齐添加字符
demo = 'jojo'
res1 = demo.rjust(5, '*')
res2 = demo.ljust(5, '*')
res3 = demo.center(12, '*')
print(res1)
print(res2)
print(res3)
如何替换字符串中的不需要的字符
string = ' i am spiderman '
res1 = string.strip()
res2 = string.lstrip()
res3 = string.rstrip()
res4 = string.replace(' ', '')
res5 = re.sub('\s', '', string)