How to Print a String Multiple Times in Python?

Estimated read time 1 min read

To print a string multiple times in Python, you can use the string multiplication operator (*) with the desired number of repetitions as the operand. Here’s an example:

my_string = "Hello, World!"
num_repetitions = 3

print(my_string * num_repetitions)

Output:

Hello, World!Hello, World!Hello, World!

In the above example, the my_string variable contains the string that we want to print multiple times, and num_repetitions contains the number of times we want to repeat the string. The * operator is used to repeat the string num_repetitions times, and the resulting string is printed to the console using the print() function.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply