简体   繁体   English

python 基本问题如何在不使用 for 循环和字符串的情况下多行打印名称 10 次

[英]python basic question how to print the name 10 times in multiple lines without using for loop and in a string

name = input("What's your name?? ")
print(10 * name  ) 

prints the name 10 times in a row but if I want the name to be printed in columns 10 times how should I do thanks连续打印名称 10 次,但是如果我希望将名称在列中打印 10 次,我该怎么做谢谢

You can simply append a newline character at the end of the name:您可以在名称末尾简单地 append 换行符:

name = input("What's your name??")
print(10 * (name + '\n')) 

\n is the newline character - anything printed after it will go to the next line. \n是换行符 - 在它之后打印的任何内容都会 go 到下一行。

name = input("What's your name?? ")
print(10 * (name+"\n")  )

You can print 10 times your name, using '\n' (the new line character) as a separator:您可以使用 '\n' (换行符)作为分隔符打印您的姓名的 10 倍:

name = input("What's your name??")
print(*(name for i in range(10)), sep='\n')

You could also use itertools.repeat :您也可以使用itertools.repeat

from itertools import repeat

name = input("What's your name??")
print(*repeat(name, 10), sep='\n')

for i in range(1,11,+1): #by using for loop i=name for i in range(1,11,+1): #通过使用 for 循环 i=name
print(i)打印(一)

name = input("What's your name?? ")
print(10 * (name+'\n')) 

you can use from the above code it is the beautiful character of python, but I suggest you to use of:您可以从上面的代码中使用它是 python 的漂亮字符,但我建议您使用:

name = input("What's your name?? ")
for i in range(10):
    print(name)

that will be the real coder's work这将是真正的编码员的工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM