1print 变量

abc = False

joke_string = "Isn't that joke so funny?! %r"

print joke_string %abc

结果:

Isn't that joke so funny?! False

若改成下面这样:

print joke_string + abc

会报错: 

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'bool' objects

2 报错:not all arguments converted during string formatting

发生这个错误的原因是写的%的格式化字符串数量大于给出的变量数量。

例如:

>>> a=123
>>> b=234
>>> c=456

>>> print "%s,%s" %(a,b,c)

 

若是:

>>> print "%s,%s" %a

就会报 TypeError: not enough arguments for format string

相关文章:

  • 2022-01-12
  • 2022-02-22
  • 2022-12-23
  • 2021-11-03
  • 2021-06-07
  • 2021-05-18
  • 2021-08-11
猜你喜欢
  • 2021-10-07
  • 2021-09-16
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
  • 2021-09-29
相关资源
相似解决方案