from __future__ import print_function
import sys
from time import sleep
fp = sys.stdout
print('Do you want to continue (Y/n): ', end='')
# fp.flush()
sleep(5)
I don't know whether I am asking the right question. I have found many similar questions on StackOverflow but none of them were useful — They lacked details. Why does the print works after sleep is executed in this case? If I uncomment fp.flush() then print works first. Why is this happening even when print is present before sleep?