TypeError: not all arguments converted during string formatting问题解决

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

原因: % 操作符只能直接用于字符串('123'),列表([1,2,3])、元组
解决方法:
>>> print 'str= %s' % (str,)
str= (1, 2, 3)
也可以用:
>>> print 'str= %s,%s,%s' % str
str= 1,2,3

猜你喜欢

转载自blog.csdn.net/qq646748739/article/details/78323877
今日推荐