1、find 方法

在一个较长的字符串中查找子字符串,返回子串所在位置的最左端索引,如果没有则返回-1

 >>> 'lihuipeng.blog.51cto.com'.find('blog')
10
>>> 'lihuipeng.blog.51cto.com'.find('lhp')
-1

2、join 方法

用指定的连接符连接序列变成字符串:'连接符'.join(序列)

 >>> seq = ['1','2','3']
>>> sep = '+'
>>> sep.join(seq)
'1+2+3'

>>> dir = '','usr','bin','env'
>>> dir
('', 'usr', 'bin', 'env')
>>> '/'.join(dir)
'/usr/bin/env'

3、lower 方法

返回字符串的小写字母版

4、replace 方法

返回某字符串的所有匹配项均被替换之后得到的新字符串

 >>> 'This is a test'.replace('is','eez')
'Theez eez a test'

5、split 方法

以某个分隔符分隔字符串返回列表:'字符串'.split(分隔符)

 >>> '1+2+3'.split('+')
['1', '2', '3']

>>> '/usr/bin/env'.split('/')
['', 'usr', 'bin', 'env']

6、strip 方法

返回去除两侧空格的字符串

 >>> '    lihuipeng.51cto.blog.com   '.strip()
'lihuipeng.51cto.blog.com'
>>> ' *!lihuipeng.51cto.blog.com*! '.strip(' *!')
'lihuipeng.51cto.blog.com'

原来这东西还可以指定需要去掉的字符

7、translate 方法

替换单个字符串,在使用前需要先生成一个转换表

 >>> from string import maketrans
>>> table= maketrans('cs','kz')
>>> len(table)
256
>>> 'this is an incredible test'.translate(table)
'thiz iz an inkredible tezt'