如何在 Python 中用 circle for 重复一个字符串 N 次(由用户给出)?

How to repeat a String N times (given by the user ) with cicle for in Python?

我想将一个字符串重复 N 次,而 N 是我用循环给出的。我在 java 中有一个示例,但我不知道如何在 Python 中执行此操作。

int a;

    System.out.print(" Numero de vezes: ");
    a=sc.nextInt();

         for (int i = 0; i < a ; i++)
    {
        System.out.println(" Hello");
    }

我试过了

a=int(input("How many times: ")

for i in range(a)
   print "hello"

只需捕获用户输入。您甚至不需要 for 循环,只需使用带换行符的字符串乘法即可:

data = input('Enter number: ')
print('Hello\n' * int(data))

在您的 post 中,您缺少整数转换中的右括号和循环中的冒号:

a = int(input('Enter number: '))

for i in range(a):
   print('Hello')