> TypeError: sequence item 0: expected str instance, int found的解决办法
TypeError: sequence item 0: expected str instance, int found的解决办法小例子:```pythona = ['1','2','3',1]print(' '.join(a))123以为会打印 1 2 3 1```python结果报了错Traceback (most recent call last):File "C:/Users/Admini
·
TypeError: sequence item 0: expected str instance, int found的解决办法
小例子:
```python
a = ['1','2','3',1]
print(' '.join(a))
1
2
3
以为会打印 1 2 3 1
```python
结果报了错
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
1
2
3
4
上网查了资料,说list包含数字,不能直接转化成字符串。
解决办法:
print(" ".join('%s' %id for id in list1))
即遍历list的元素,把他转化成字符串。这样就能成功输出1 2 3 1了。
更多推荐



所有评论(0)