Last active
January 9, 2024 09:50
-
-
Save laixintao/af65e7209bab5275d1f1dff84d1738c0 to your computer and use it in GitHub Desktop.
File mode quiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hint: read this link before answering: | |
# https://stackoverflow.com/questions/1466000/difference-between-modes-a-a-w-w-and-r-in-built-in-open-function | |
with open("a.txt", "w") as f: | |
f.write("abcd") | |
with open("a.txt", "r+") as f: | |
f.write("x") | |
x = f.read(1) | |
print(x) | |
f.write("y") | |
x = f.read(1) | |
print(x) | |
f.write("z") | |
x = f.read(1) | |
print(x) | |
with open("a.txt", "r") as f: | |
print(f.read()) | |
# question: what is the output of this script? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment