Possible Duplicate:
Python, Printing multiple times,
I'd like to know how to print a string such as "String" 500 hundred times?
Possible Duplicate:
Python, Printing multiple times,
I'd like to know how to print a string such as "String" 500 hundred times?
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
.