1.find(在一个较长的字符串中查找子串,它返回的是子串所在位置的最左端索引,如果没有就会返回-1)

print('how are you?,it\'s ok'.find('are'))

title = 'everything has two sides'

print(title.find('s'))#返回的是子串所在位置的最左端索引
print(title.find('everything'))
print(title.find('you')) #如果没有就会返回-1

title = 'everything has two sides'
print(title.find('e',4,17))#还可以提供查找的范围

2.join(连接序列中的元素,连接的元素必须是字符串)

str = "-"
seq = ('1','2','3','4','5') # 字符串序列
print(str.join( seq ))

3.lower(返回字符串的小写字母版)

print('TOMMORROW IS LEFT'.lower())
name = 'JACK'
names = ['jack','jay','jane']
if name in names:
    print('find it')
elif name.lower() in names:
    print('very good')
else:
    print('nothing')

4.replace(返回某字符串的所有匹配项均被替换之后得到字符串)

print('i love you'.replace('you','nothing'))

5.split(将字符串分隔成序列,是join的逆方法)

print('1+2+3+4+5'.split('+'))
print('/usr/bin/env'.split('/'))
print('hello world'.split()) # 如果不提供分隔符,程序会把所有的空格作为分隔符

6.strip(返回去除两侧空格的字符串,但不包括字符串内部)

print('             hello  world                      '.strip())

 

posted on 2016-12-01 19:02  月008  阅读(651)  评论(0编辑  收藏  举报