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
时间: 2024-10-14 00:37:44