Bird
Raised Fist0

What does the function os.path.basename(path) return?

easy🧠 Conceptual Q2 of Q15
Python - Standard Library Usage
What does the function os.path.basename(path) return?
AThe file name or last part of the path
BThe file extension
CThe absolute path
DThe directory name of the path
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.path.basename behavior

    This function returns the last part of the path, usually the file or folder name.
  2. Step 2: Differentiate from other functions

    dirname returns the folder part, abspath returns full absolute path, and extension is separate.
  3. Final Answer:

    The file name or last part of the path -> Option A
  4. Quick Check:

    basename(path) = last part of path [OK]
Quick Trick: basename gets the last part of a path [OK]
Common Mistakes:
MISTAKES
  • Confusing basename with dirname
  • Expecting basename to return extension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes