[英]How to print multiple lines and make each output line different?
I want to make a script where i can print multiple lines (was thinking with a for or while loop) and every line that outputs is different like: 我想制作一个脚本,在其中我可以打印多行(正在考虑for或while循环),并且输出的每一行都是不同的,例如:
Output:
Hello.1
Hello.2
Hello.3
Is it posible to make with python? 可以用python制作吗?
I am afraid of answering this simple question but here is the answer using a for
loop 我害怕回答这个简单的问题,但这是使用for
循环的答案
for i in range(1,4):
print ("Hello.%s" %i)
# Hello.1
# Hello.2
# Hello.3
Second alternative way is using format
第二种替代方法是使用format
for i in range(1,4):
print ("Hello.{}".format(i))
Third alternate is using f
-strings as 第三选择是使用f
-strings作为
for i in range(1,4):
print (f"Hello.{i}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.