Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Python - Standard Library Usage
What will be the output of this code?
import os
print(os.path.exists('nonexistent.txt'))
AFalse
BTrue
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.path.exists()

    This function returns True if the file exists, False otherwise.
  2. Step 2: Check file existence

    The file 'nonexistent.txt' does not exist, so the function returns False.
  3. Final Answer:

    False -> Option A
  4. Quick Check:

    os.path.exists() returns False if file missing [OK]
Quick Trick: os.path.exists() checks if file or folder exists [OK]
Common Mistakes:
  • Expecting True for missing file
  • Confusing None with False
  • Assuming function raises error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes