Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
Python - Standard Library Usage
Identify the error in this code:
import os
path = os.path.join('folder', '/file.txt')
print(path)
ANo error, prints 'folder/file.txt'
BSecond argument is absolute, so 'folder' is ignored
CSyntax error due to missing comma
Dos.path.join cannot join strings
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.path.join behavior with absolute paths

    If any argument is absolute (starts with '/'), all previous parts are discarded.
  2. Step 2: Analyze given arguments

    Second argument '/file.txt' is absolute, so result is '/file.txt' only.
  3. Final Answer:

    Second argument is absolute, so 'folder' is ignored -> Option B
  4. Quick Check:

    Absolute path in join discards previous parts [OK]
Quick Trick: Absolute path in join resets the path [OK]
Common Mistakes:
  • Expecting concatenation
  • Ignoring absolute path behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes