For Python version 3 or higher, you can just provide flush=True as a keyword argument to the print function:
print('foo', flush=True)
For Python 2, you can just call file.flush() with the print statement:-
import sys
print('delayed output')
sys.stdout.flush()
You can use the following video tutorials to clear all your doubts:-