capitalize方法
>>> str1 = 'i love the fishc,com'
>>> srt1.capitalize()
'I love the fishc,com'
casefold方法
>>> srt1 = 'DACISxiaoxie'
>>> srt1.casefold()
'dacisxiaoxie'
center方法
>>> srt1.center(20)
' DACISxiaoxie '
count方法
>>> srt1.count('x',0,8)
1
endwith方法
>>> srt1.endswith('xie')
True
expandtabs方法
>>> str3 = 'i \tlove\tfishc.com'
>>> str3.expandtabs()
'i love fishc.com'
find方法
>>> str3.find('i')
0
>>> str3.find('sd')
-1
istitle方法
>>> str4 = 'Fishc'
>>> str4.istitle()
True
join方法
>>> str4.join('1234')
'1Fishc2Fishc3Fishc4'
partition方法
>>> str4.partition('i')
('F', 'i', 'shc')
split方法
>>> str4.split('s')
['Fi', 'hc']
strip方法
>>> str5.strip()
'2223 ssss'
>>> str5.strip('s')
' 2223 '
translate方法
>>> str5.translate(str.maketrans('s','3'))
' 2223 3333'
格式化字符串
format方法
>>> '{0} love {1}'.format('i','you')
'i love you'
>>> '{a} love {b}'.format(a = 'i',b = 'you')
'i love you'
>>> '{{0}}'.format('budayin')
'{0}'
%
>>> '%c %c %c' % (97,98,99)
'a b c'
>>> '%s' % 'you and me'
'you and me'
>>> '%d + % d = %d' % (4,5,4+5)
'4 + 5 = 9'
>>> '%o' % 10
'12'
>>> '%x' % 10
'a'
>>> '%f' % 10.888
'10.888000'
>>> '%e' % 10.888
'1.088800e+01'
>>> '%f' % 10.88858585858854
'10.888586'
>>> '%5.2f' % 10.88858585858854
'010.89'
>>> '%-10g' % 10.8858
'10.8858 '
>>> '%10g' % 10.8858
' 10.8858'
>>> '%#o' % 10
'0o12'
>>> '%#x' % 20
'0x14'