First, create a test.py file, as follows:
for i in range(1,21): print("the number is {}".format(i))
Open a terminal, enter test.py folder where the file, run:
python<test.py>test.log
Then, you can see the folder test.log generate a file, the contents of print output is saved in test.log years.