1

I wanted to test if I could have some sort of slower writing option for a program I am building so I made this really simple script that prints a letter from a string with end = '' and then waits 0.2 seconds. I tried running it in the command prompt but instead of printing every letter with an interval it waits the whole duration (so 0.2 times the amount of letters) and then prints it all together.

I tried a few things including removing the end parameter and it works just fine without it. Then I tested running it in another environment (a Jupyter notebook) and it worked as it should.

import time

string = "hello world"

for i in string:
    time.sleep(0.2)
    print(i, end = '')

I expected it to print one letter, wait 0.2 seconds, then the next one and so on but it instead waits the whole duration and then everything together.

  • Probably 0.2s is too fast that you couldn't notice the difference. Change it to say 2 seconds to notice it. By the way, do you need the **end = ''** in your `print` statement? – Hari Jun 20 '19 at 00:46
  • @Hari They want it to slowly print "hello world", `end = ""` removes the automatic `\n` – tgikal Jun 20 '19 at 00:48
  • launch your script with ```python -u``` to disable buffering and it should work without any code changes. – flappix Jun 20 '19 at 00:55

0 Answers0