字符串

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'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值