Skip to content

Instantly share code, notes, and snippets.

@laixintao
Last active January 9, 2024 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laixintao/af65e7209bab5275d1f1dff84d1738c0 to your computer and use it in GitHub Desktop.
Save laixintao/af65e7209bab5275d1f1dff84d1738c0 to your computer and use it in GitHub Desktop.
File mode quiz
# 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