@Patrick Artner's answer is correct, but I just wanted to add on a use case that will work in certain IDE's as well as the Windows command prompt.
In order to get the desired animation, you have to also include sys
, and use sys.stdout.flush()
in each iteration of the loop, like so:
import time
import sys
snort = "SNoooOOO000oooRT"
for char in snort:
sys.stdout.flush()
time.sleep(0.1)
print(char,end='')
If you do not do this in the command prompt (or certain IDE's), the program will output the entire string after it has slept for each iteration of the loop.
You can actually also force print()
to flush the output buffer by including the flush
parameter in your print statement. So you can avoid importing sys
if you do this:
print(char,end='', flush=True)