更改行 \n 不起作用

changing line \n doesn't work

我的 \n 不工作 这是我的代码:

s = 0
a = 0
w = 0
h = 0
stats = "1. Strength - ", s, "\n2. Agility - ", a, "\n3. Wisdom - ", w, "\n4. Health - ", h
print(stats)

当尝试启动程序时我得到这个:

('1. Strength - ', 0, '\n2. Agility - ', 0, '\n3. Wisdom - ', 0, '\n4. Health - ', 0)

顺便说一句,我需要我的 sawh 变量作为整数。

Python 正在打印您创建的列表。如果您想单独查看每个项目:

>>> for s in (stats): print(s)
...
1. Strength -
0

2. Agility -
0

3. Wisdom -
0

4. Health -
0

Liturgist awnser 是一种打印值元组的方法,就像您拥有的那样,但我认为您想将它们连接起来。不要使用 , 连接,+ 用于这些目的。我的替代方法。

stats = "1. Strength - " +str(s)+ "\n"+"2. Agility - "+ str(a)+ "\n" + "3. Wisdom - "+  str(w) + "\n" + "4. Health - "+ str(h)