array = [1,2,3]
print("List: ")
for i in array:
print(i, end=" ")
-------
我希望输出看起来像List: 1 2 3
如何在Python中实现这一目标?
答案 0 :(得分:2)
在第一个打印语句中提供end
参数的值
array = [1,2,3]
print("List: ",end="")
for i,x in enumerate(array):
print(i, end=" ") if len(array) != x else print(i)
print("foo")
列表:1 2 3
foo
答案 1 :(得分:0)
print(f"List: {array[0]} {array[1]} {array[2]}")
答案 2 :(得分:0)
也许:
>>> a = [1,2,3]
>>> b = [str(i) for i in a]
>>> print "List :"+", ".join(b)
List :1, 2, 3