Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - File Handling Fundamentals
What will be the output of this code?
from pathlib import Path
p = Path('folder') / 'subfolder' / 'file.txt'
print(p.parts)
A('folder/subfolder/file.txt',)
B['folder', 'subfolder', 'file.txt']
C['folder/subfolder/file.txt']
D('folder', 'subfolder', 'file.txt')
Step-by-Step Solution
Solution:
  1. Step 1: Understand Path.parts attribute

    The parts attribute returns a tuple of each part of the path as separate strings.
  2. Step 2: Analyze the given path

    The path is 'folder/subfolder/file.txt', so parts will be ('folder', 'subfolder', 'file.txt').
  3. Final Answer:

    ('folder', 'subfolder', 'file.txt') -> Option D
  4. Quick Check:

    Path.parts returns tuple of path parts [OK]
Quick Trick: Path.parts returns a tuple of path components [OK]
Common Mistakes:
  • Expecting a list instead of tuple
  • Getting full path as one string
  • Confusing parts with name or stem

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes