Bird
0
0

Which of the following is the correct syntax to get the folder name from a path stored in variable path?

easy📝 Syntax Q12 of 15
Python - Standard Library Usage
Which of the following is the correct syntax to get the folder name from a path stored in variable path?
Aos.path.basename(path)
Bos.path.dirname(path)
Cos.path.join(path)
Dos.path.exists(path)
Step-by-Step Solution
Solution:
  1. Step 1: Identify function to get folder name

    os.path.dirname(path) returns the directory part of the path.
  2. Step 2: Check other options

    basename() returns file name, join() combines paths, exists() checks path existence.
  3. Final Answer:

    os.path.dirname(path) -> Option B
  4. Quick Check:

    Folder name = os.path.dirname(path) [OK]
Quick Trick: Use os.path.dirname() to get folder name from path [OK]
Common Mistakes:
  • Using basename() to get folder
  • Calling join() with one argument
  • Confusing exists() with dirname()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes