python初学者:格式化行

python初学者:格式化行,python,formatting,format,Python,Formatting,Format,我正在完成我必须为作业编写的代码,但问题是当我打印代码时,它的格式不正确。我目前有一个列表中的歌曲行,当我打印出来时,列表中包含的括号不是我想要的。我还希望每行都有一个新的空格,我尝试使用“\n”换行符来设置它,但它也不起作用。附件是我的代码,任何与此格式的帮助将是很好的。谢谢 def main(): 你在添加stanzal,这是一个列表 你也可以这样做 oldMac += "\n".join(stanza1) 把这一节的内容去掉 或者可能是最好的解决方案 stanza = """Old Ma

我正在完成我必须为作业编写的代码,但问题是当我打印代码时,它的格式不正确。我目前有一个列表中的歌曲行,当我打印出来时,列表中包含的括号不是我想要的。我还希望每行都有一个新的空格,我尝试使用“\n”换行符来设置它,但它也不起作用。附件是我的代码,任何与此格式的帮助将是很好的。谢谢

def main():

你在添加stanzal,这是一个列表

你也可以这样做

oldMac += "\n".join(stanza1)
把这一节的内容去掉

或者可能是最好的解决方案

stanza = """Old MacDonald had a farm, E-I-E-I-O,
          And on his farm he had a {0}, E-I-E-I-O
          With a {1}-{1} here - 
          And a {1}-{1} there - 
          Here a {1} there a {1}
          Everywhere a {1}-{1}
          Old MacDonald had a farm, E-I-E-I-O""".format(animal, animalSound)
换线

print stanza1

输出

What animal? cow
What sound does a cow make? moo

Old MacDonald had a farm, E-I-E-I-O,
And on his farm he had a cow, E-I-E-I-O
With a moo-moo here - 
And a moo-moo there - 
Here a moo there a moo
Everywhere a moo-moo
Old MacDonald had a farm, E-I-E-I-O
print stanza1
print '\n'.join(stanza1)
What animal? cow
What sound does a cow make? moo

Old MacDonald had a farm, E-I-E-I-O,
And on his farm he had a cow, E-I-E-I-O
With a moo-moo here - 
And a moo-moo there - 
Here a moo there a moo
Everywhere a moo-moo
Old MacDonald had a farm, E-I-E-I-O