<分区> 分区>
我从this question中学到了可以在 Python 中使用 ", ".join(var) 连接数组中的值。此代码适用于字符串,例如:
var = ["hello","world"]
print (", ".join(var))
给出 hello, world 的输出,这正是我想要的。
但是,当我在数组中使用数字时:
var = [1,2,3]
print (", ".join(var))
它给出错误信息:
Traceback (most recent call last):
File "C:\path\test.py", line 2, in <module>
print (", ".join(var))
TypeError: sequence item 0: expected str instance, int found
然而,我希望输出为:
1, 2, 3
有没有其他方法可以打印所有数字,并且可以增加数字,这样我就可以拥有任意数量的数字?
