← Quiz: Context Managers: all 10 questions
Quiz: Context Managers · Question 10 of 10
What happens if you call f.read() after the with open(...) as f: block has ended?
What happens if you call f.read() after the with open(...) as f: block has ended?
- A.It returns an empty string
- B.It reopens the file
- C.It returns None
- D.It raises ValueError because the file is closed
Answer & explanation
Correct answer: It raises ValueError because the file is closed
The file was closed when the block ended.
Can you get the rest right without peeking?
Take the timed Quiz: Context Managers quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →