Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display string multiple times

Tags:

python

People also ask

How do I print 10 times a word in Python?

Console. WriteLine( string. Concat(Enumerable. Repeat("Hello\n", 10)) );

How do you return a string multiple times in Python?

In Python, we utilize the asterisk operator to repeat a string. This operator is indicated by a “*” sign. This operator iterates the string n (number) of times. The “n” is an integer value.

How do I print the same line twice in Python?

To print on the same line in Python, add a second argument, end=' ', to the print() function call. print("It's me.")


Python 2.x:

print '-' * 3

Python 3.x:

print('-' * 3)

The accepted answer is short and sweet, but here is an alternate syntax allowing to provide a separator in Python 3.x.

print(*3*('-',), sep='_')