Python3字符串格式化format

字符串格式化format

case1 位置参数

>>> "{0} love {1}.{2}".format("I", "FishC", "com")
'I love FishC.com'

case2 关键字参数

>>> "{a} love {b}.{c}".format(a="I", b="FishC", c="com")
'I love FishC.com'

'{0:.1f}.{1}'.format(27.658,"GB")
'27.7.GB'

>>> '%c' % 97
'a' 
>>> '%c %c %c' % (97, 98, 99)
'a b c'

'%s' % 'hello xixi'
>>> '%d + %d = %d' % (4,5, 4+5)
'4 + 5 = 9'
>>>

>>> num = [23,54,5,7,78,8,9,0,-3]
>>> max(num)
78
>>> num.append('a)
  File "<stdin>", line 1
    num.append('a)
                 ^
SyntaxError: EOL while scanning string literal
>>> num.append('a')
>>> num
[23, 54, 5, 7, 78, 8, 9, 0, -3, 'a']
>>> max(num)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'str' and 'int'
>>> num.pop()
'a'
>>> e
elif        else        enumerate(  eval(       except      exec(       exit(       
>>> enumerate(num)
<enumerate object at 0x7f885eee4798>
>>> list(enumerate(num))
[(0, 23), (1, 54), (2, 5), (3, 7), (4, 78), (5, 8), (6, 9), (7, 0), (8, -3)]
>>>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值