Writing to the standard output stream with formatting

Suppose you would like to control the format of output to the standard output stream (i.e. your computer screen, unless you are redirecting it), rather than to a particular file. This is easy. The standard output stream is also a file object. It is called sys.stdout. You don't need to open it. Here is the above example that writes the formatted output to your screen:

import sys
sys.stdout.write("{0:5.2f} {1:5.2f}\n".format(x,x*x))