【问题标题】:In python, how can I print an imput X times in different lines? [duplicate]在 python 中,如何在不同的行中打印输入 X 次? [复制]
【发布时间】:2020-05-18 17:21:43
【问题描述】:

我想在一个变量中打印一个输入,然后多次打印该变量,但事情是这样的,我希望它在不同的行中。是否可以?谢谢!

song = input('song ')   

favorite = song 
print(favorite * 3)

song lala land
lala landlala landlala land

【问题讨论】:

  • @khelwood 是的,我也看到了,但这不是我要的。我之前没有找到类似我的问题的东西。谢谢!

标签: python python-3.x


【解决方案1】:

您可以使用列表并在其上使用'\n'.join

song = input('song ')

favorite = song

print('\n'.join([favorite] * 3))

或者你可以利用print函数的sep参数:

print(*([favorite] * 3), sep = '\n')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多