python print
https://blog.csdn.net/funnyPython/article/details/78141649
TypeError: sequence item 0: expected str instance, int found
小例子:
a = ['1','2','3',1]print(' '.join(a))
以为会打印 1 2 3 1
结果报了错
Traceback (most recent call last):File "C:/Users/Administrator/Desktop/onetest.py", line 188, in <module>
print(' '.join(a))
TypeError: sequence item 3: expected str instance, int found
上网查了资料,说list包含数字,不能直接转化成字符串。
解决办法:
print(" ".join('%s' %id for id in list1))
即遍历list的元素,把他转化成字符串。这样就能成功输出1 2 3 1了。
以上是 python print 的全部内容, 来源链接: utcz.com/z/389346.html