Reputation: 149
I want to create a function which prints every character of a string with a small time break. I want them to print all the characters in the same line, so I use end
. It is printing all of them in same line but there is a small delay in start and then it print all characters at once.
import time
def delay_print(a):
for i in a:
print(i ,end = "")
time.sleep(0.3)
delay_print("om")
Upvotes: 0
Views: 70
Reputation: 2812
The print call needs flush
to be set to True, otherwise the output is buffered and printed at the end, as explained in this question.
import time
def delay_print(a):
for i in a:
print(i, end = "", flush = True)
time.sleep(0.3)
print()
delay_print("om")
Output (After a second):
om
Upvotes: 3