File Handling

Python provides functions to handle files: opening, reading, writing, and closing files.

Opening a File

file = open("example.txt", "w")  # Open a file in write mode
file.write("Hello, World!")
file.close()  # Close the file

Reading from a File

file = open("example.txt", "r")  # Open file in read mode
content = file.read()
print(content)  # Output: Hello, World!
file.close()