Bird
0
0

Which of the following is the correct way to join folder 'docs' and file 'file.txt' into a path using os.path?

easy📝 Syntax Q3 of 15
Python - Standard Library Usage
Which of the following is the correct way to join folder 'docs' and file 'file.txt' into a path using os.path?
Aos.path.join('docs' + 'file.txt')
Bos.path.join('docs', 'file.txt')
Cos.path.join('docs/file.txt')
Dos.path.join('docs', '/file.txt')
Step-by-Step Solution
Solution:
  1. Step 1: Use os.path.join with separate arguments

    The function takes multiple arguments and joins them with the correct separator.
  2. Step 2: Avoid incorrect concatenations

    Concatenating strings inside join or using absolute paths as second argument causes errors or ignores first part.
  3. Final Answer:

    os.path.join('docs', 'file.txt') -> Option B
  4. Quick Check:

    Join paths with separate arguments [OK]
Quick Trick: Pass each folder/file as separate argument to join [OK]
Common Mistakes:
  • Concatenating strings before join
  • Using absolute path as second argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes