How can I take the output data that my program gives me and put that into a text file or a CSV file?

How to put data from a python code into an excel sheet or some form of tabular datasheet?