为什么我的工作不起作用,我怎样才能让它发挥作用
x = "text1"
c = "text2"
b=[]
for i in range(5):
xx=(c + " | " + x + "\n")
b.append(xx)
print (b)
答案 0 :(得分:0)
如果您只想打印文本而不是列表,请使用str.join
# ...
print(''.join(b))
# or like this:
text = ''.join([(c + " | " + x + "\n") for _ in range(5)])
print(text)
# or python 3.6 style
text = ''.join(f"{c} | {x}\n" for _ in range(5))