Open files for reading or writing with proper handling.
Source Code
# Writing to a file
with open("myfile.txt", "w") as file:
file.write("Hello, world!")
# Reading from a file
with open("myfile.txt", "r") as file:
content = file.read()
print(content)