python中字符串处理函数

2016-10-20  本文已影响0人  洛神鬼道

查找

title_str="   This is a sentence. This is other sentence   "
print(title_str.find('This',10,20))
print(title_str.find('This'))

join拼接

dirs='','usr','local','bin'
print('/'.join(dirs))

小写字母

name='Grubby'
names= ['grubby','green','lucy']
if name.lower() in names:
    print('found it!')

替换

print('this is a test'.replace('is','rep'))

切分

print('/usr/local/bin'.split('/'))

去除空格

print('   with whitespace   '.strip())
上一篇下一篇

猜你喜欢

热点阅读