我们有一个列表:
myList = [1, "two"]
我想将它打印出来,通常我会使用类似这样的方法:
而想要打印出来,通常我会使用类似下面这样的方式:
"{0} and {1}".format(*myList)
但您也可以这样做:
" and ".join(myList)
但不幸的是:
>>> " and ".join(myList)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found
为什么它不会自动将接收到的列表转换为字符串?
在什么情况下您不需要将它们转换为字符串?我是否遗漏了某些微小的情况?