Bird
0
0

Find the bug in this code snippet:

medium📝 Debug Q7 of 15
Python - Standard Library Usage
Find the bug in this code snippet:
import os
path = os.path.basename('folder/subfolder')
print(path)
AShould use os.path.dirname instead of basename
Bbasename returns 'subfolder', no bug
CMissing import statement
Dbasename requires absolute path
Step-by-Step Solution
Solution:
  1. Step 1: Check os.path.basename behavior

    It returns the last part of the path, here 'subfolder'.
  2. Step 2: Verify correctness

    Code runs fine and prints 'subfolder', so no bug.
  3. Final Answer:

    basename returns 'subfolder', no bug -> Option B
  4. Quick Check:

    basename returns last path part correctly [OK]
Quick Trick: basename returns last folder or file name [OK]
Common Mistakes:
  • Thinking dirname needed
  • Expecting error without absolute path

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes