我找不到正确的输出。假设我有两张单子,单子A和单子B
list A = [1,2,3]
list B = [2,3,4]
我想打印一份如下的声明。。你知道吗
Solution A : 1 2 3
Solution B : 2 3 4
到目前为止我所做的是。。。你知道吗
A = config.mList
B = config.sList
return 'Solution A: %s \nSolution B: %s' %(A, B)
这只是打印出来的
Solution A: ['17', '4', '8', '11']
Solution B: ['9', '18', '13']
使用join函数将列表转换为字符串,然后格式化它们。你知道吗
在Python 2.x中:
在Python 3.x中:
请注意,python3.x中的
print
函数会自动调用它提供的对象上的str
。其中' '.join
要求对象已经是字符串,因此要确保使用:或:
可以使用^{} 和^{} :
但是请注意,在使用
str.join
之前,列表中的项必须是字符串。在示例中,您给出了整数列表。所以,如果你有这些,你可以这样做:这里有一个关于^{} 的参考。你知道吗
相关问题 更多 >
编程相关推荐