1

Possible Duplicate:
Python, Printing multiple times,

I'd like to know how to print a string such as "String" 500 hundred times?

Community
  • 1
  • 1
Thi G.
  • 1,578
  • 5
  • 16
  • 27

1 Answers1

18

You can use repetition (*):

print('String' * 500)

In this way Python will first create the whole string ("StringStr...String") in memory and only then will print it.

If you don't want to use so much memory, then you can use a for loop:

for i in range(500):
    print('String', end='')
print()

end='' is needed to prevent Python from printing end-of-line characters after each print. print() at the end is needed to print the end-of-line character after the last print.

citxx
  • 2,525
  • 17
  • 40