1. 从列表删除元素
.insert(位置,' ')
.remove()
del 语句
.pop()
.count(' ')
.index(' ', start, end)
.reverse()
.sort() 或者 .sort(reverse=Ture) 默认为False
2. 字符串方法
1) .capitalize() 将小写字母改成大写字母
>>> str2 = 'xiaoxiezimu'
>>> str2.capitalize()
'Xiaoxiezimu'
2).casefold() 将大写字母改成小写字母
>>> str3 = 'DAXIEzimu'
>>> str2.casefold()
'daxiezimu'
3) .endswith('') 字符串是否以制定字符结尾,若是,返回True,若否,返回False
>>> str1 = 'xiaojiayushiSB'
>>> str1.endswith('sb')
False
>>> str1.endswith('SB')
True
4) .center(数字) 以指定的数字中间对齐
>>> str1 = 'xiaojiayushiSB'
>>> str1.center(40)
' xiaojiayushiSB '
5).count('') 计算指定字符的个数
>>> str1 = 'xiaojiayushiSB'
>>> str1.count('i')
3
6).find('') 找出指定字符出现在字符串的位置,若制定字符不在字符串中,返回值-1
>>> str2 = 'I\tlove\tfishC.com!'
>>> str2.find('com')
13
7).title('') 标题化字符串
>>> str3 = 'FishC'
>>> str3.title()
'Fishc'
8).istitle() 判断字符串是否是标题化字符串
>>> str3 = 'FishC'
>>> str3.istitle()
False
9).join('') 将字符串分隔开来连接
>>> str3 = 'FishC'
>>> str3.join('123')
'1Fishc2Fishc3'
10).pattition('') 将字符串以指定字符分开,形成元组
>>> str12 = 'I love fishc.com!'
>>> str12.partition('ov')
('I l', 'ov', 'e fishc.com!')
11).replace(old, new) 将旧的字符串替换成新的字符串
>>> str5 = 'I love fishc.com!'
>>> str5.replace('fishc','FishC')
'I love FishC.com!'
12) .split('') 将字符串以指定字符分开,形成列表
>>> str13 = 'I love fishc.com!'
>>> str13.split('i')
['I love f', 'shc.com!']
13).swapcase() 将大小写字母进行转换
>>> str7 = 'FishC'
>>> str7.swapcase()
'fISHc'
14).translate( str.maketrans(old, new) ) 将旧的字符串替换成新的字符串
>>> str8 = 'aaaabbbbbaaaa'
>>> str8.translate(str.maketrans('a','b'))
'bbbbbbbbbbbbb'