2024-04-20 01:48:36 发布
网友
为什么我的\n不起作用?我如何才能使它起作用
x = "text1" c = "text2" b=[] for i in range(5): xx=(c + " | " + x + "\n") b.append(xx) print (b)
如果您只想打印文本而不是列表,那么使用str.join
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))
如果您只想打印文本而不是列表,那么使用
str.join
相关问题 更多 >
编程相关推荐