标签:
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
标签:
原文地址:http://www.cnblogs.com/guohuino2/p/5950378.html