READ AND WRITE TO A FILE IN PYTHON

# Write to a file
with open("example.txt", "w") as file:
    file.write("Hello, World!")

# Read from the file
with open("example.txt", "r") as file:
    print(file.read())  # Output: Hello, World!
Python

Leave a Reply

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


error: Content is protected !!
Scroll to Top
MacroNepal
Verified by MonsterInsights