file = open("example.txt", "r") content = file.read() print(content) file.close()
Hello, world! This is a new line.
file = open("example.txt", "w") file.write("Hello, world!") file.close()
file = open("example.txt", "a") file.write("\nThis is a new line.") file.close()
with open("example.txt", "r") as file: content = file.read() print(content)
Hello, world! This is a new line.