Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q4 of Q15
Python - Standard Library Usage
What will be the output of this code?
import os
path = os.path.join('folder', 'subfolder', 'file.txt')
print(path)
Afolder.subfolder.file.txt
Bfolder\subfolder\file.txt
Cfolder-subfolder-file.txt
Dfolder/subfolder/file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.path.join output on Unix-like systems

    On Unix-like systems, os.path.join uses forward slashes / as separators.
  2. Step 2: Check the given folders and file

    Joining 'folder', 'subfolder', and 'file.txt' results in 'folder/subfolder/file.txt'.
  3. Final Answer:

    folder/subfolder/file.txt -> Option D
  4. Quick Check:

    os.path.join uses OS separator [OK]
Quick Trick: os.path.join uses OS-specific separators [OK]
Common Mistakes:
MISTAKES
  • Expecting backslashes on Unix-like systems
  • Confusing separators with dots or dashes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes