admin管理员组

文章数量:1567278

代码实例

 strs=(1,2,3,4)  #创建一个集合
 strs
 (1, 2, 3,4)
 >>> print 'strs= %s ' % strs
 Traceback (most recent call last):
   File "<pyshell#43>", line 1, in <module>
     print 'strs= %s ' % str
 TypeError: not all arguments converted during string formatting

原因:1 % 操作符只能直接用于字符串(‘123’),列表([1,2,3])、元组,因此需要一一匹配操作符。

如何解决

 print 'strs= %s' % (strs,)
strs= (1, 2, 3,4)
也可以用:
print 'strs= %s,%s,%s,%s' % sstr
strs= 1,2,3,4 

本文标签: 报错argumentsTypeErrorPythonformatting