【发布时间】:2022-12-21 02:46:27
【问题描述】:
Python。有必要使 n-行数。我成功了,但是最后添加了一个空行,我该如何删除它?
a = int(input())
phrase = "Hello!"
final = f"{phrase} \n"
print (final * a)
【问题讨论】:
标签: python
Python。有必要使 n-行数。我成功了,但是最后添加了一个空行,我该如何删除它?
a = int(input())
phrase = "Hello!"
final = f"{phrase} \n"
print (final * a)
【问题讨论】:
标签: python
不要用换行符重复字符串,而是创建一个列表并加入换行符:
a = int(input())
phrase = "Hello!"
phrases = [phrase] * a
print("
".join(phrases))
【讨论】:
您的代码将如下所示:
a = int(input())
phrase = "Hello!"
final =(f"{phrase}
",end="")
【讨论】: