Skip to content

How to save to file in Python?

with open('data.txt', 'w') as my_data_file:
# After leaving the above block of code, the file is closed
# "w" overwrites the contents of the file
See also  How to print the square root of a number in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.