Bird
0
0

Which of the following is the correct way to add a new directory to Python's module search path at runtime?

easy📝 Syntax Q12 of 15
Python - Modules and Code Organization
Which of the following is the correct way to add a new directory to Python's module search path at runtime?
Asys.path.append('/my/new/path')
Bsys.add_path('/my/new/path')
Csys.path.add('/my/new/path')
Dsys.insert_path('/my/new/path')
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to modify lists in Python

    sys.path is a list, so to add an item, we use append().
  2. Step 2: Check the method names

    Only append() is a valid list method; others like add_path or insert_path do not exist.
  3. Final Answer:

    sys.path.append('/my/new/path') -> Option A
  4. Quick Check:

    Use append() to add path to sys.path [OK]
Quick Trick: Use list append() to add paths to sys.path [OK]
Common Mistakes:
  • Using non-existent sys methods like add_path
  • Trying to assign sys.path directly without list methods
  • Confusing append() with add() which lists don't have

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes