python字符串格式化_python字符串格式化

Python 2.7.12rc1 (v2.7.12rc1:13912cd1e7e8, Jun 12 2016, 05:57:31) [MSC v.1500 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.>>> str1="i love fish">>> str1[:6]‘i love‘>>> str="111eee">>> str.isalnum()

True>>> str6="i love cppc">>> str‘111eee‘>>> str6‘i love cppc‘>>> str6.splice()

Traceback (most recent call last):

File "", line 1, in

str6.splice()

AttributeError: ‘str‘ object has no attribute ‘splice‘>>> str6.split()

[‘i‘, ‘love‘, ‘cppc‘]>>> str6‘i love cppc‘>>> str6.title()‘I Love Cppc‘>>> "{a} love {b}.{c}".format(a=‘i‘,b=‘fish‘,c=‘com‘)‘i love fish.com‘>>> {0}.format("ni")

Traceback (most recent call last):

File "", line 1, in

{0}.format("ni")

AttributeError: ‘set‘ object has no attribute ‘format‘>>> "{0}".format("ni")‘ni‘>>> {{0}}.format("ni")

Traceback (most recent call last):

File "", line 1, in

{{0}}.format("ni")

TypeError: unhashable type: ‘set‘>>> "{{0}}".format("ni")

File "", line 2 "{{0}}".format("ni") ^IndentationError: unexpected indent>>> "{}".format("ni")‘ni‘>>> "{{0}}".format("ni")‘{0}‘>>> "{0:.1lf}{1}".format(27.546,GB)

Traceback (most recent call last):

File "", line 1, in "{0:.1lf}{1}".format(27.546,GB)

NameError: name ‘GB‘ is not defined>>> "{0:.1lf}{1}".format(‘27.546‘,‘GB‘)

Traceback (most recent call last):

File "", line 1, in "{0:.1lf}{1}".format(‘27.546‘,‘GB‘)

ValueError: Invalid conversion specification>>> "{0:.1lf}{1}".format(27.546,‘GB‘)

Traceback (most recent call last):

File "", line 1, in "{0:.1lf}{1}".format(27.546,‘GB‘)

ValueError: Invalid conversion specification>>> "{0:.1f}{1}".format(‘27.546‘,‘GB‘)

Traceback (most recent call last):

File "", line 1, in "{0:.1f}{1}".format(‘27.546‘,‘GB‘)

ValueError: Unknown format code ‘f‘ for object of type ‘str‘>>> ‘{0:.1lf}{1}‘.format(27.546,‘GB‘)

Traceback (most recent call last):

File "", line 1, in ‘{0:.1lf}{1}‘.format(27.546,‘GB‘)

ValueError: Invalid conversion specification>>> "{0:.lf}{1}".format(27.546,‘GB‘)

Traceback (most recent call last):

File "", line 1, in "{0:.lf}{1}".format(27.546,‘GB‘)

ValueError: Format specifier missing precision>>> "{0:.1f}{1}".format(27.546,‘GB‘)‘27.5GB‘>>> ‘%c %c %c‘ % (97,97,99)‘a a c‘>>> ‘%e‘ % 27.3342‘2.733420e+01‘>>>

fz.gif

730879-20161109000826483-1186935592.png

730879-20161109000807889-515814846.png

730879-20161109000818202-1297277783.png

原文地址:http://jsw55667.blog.51cto.com/12917062/1928207

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值