Bird
0
0

Given this code snippet:

medium📝 Predict Output Q13 of 15
Python - Modules and Code Organization
Given this code snippet:
import sys
print(sys.path[0])

What will sys.path[0] usually contain when running a script?
AThe Python installation directory
BAn empty string
CThe user's home directory
DThe directory of the script being run
Step-by-Step Solution
Solution:
  1. Step 1: Understand sys.path[0] meaning

    The first item in sys.path is usually the directory of the script being executed.
  2. Step 2: Confirm what sys.path[0] holds

    This allows Python to find modules in the same folder as the script.
  3. Final Answer:

    The directory of the script being run -> Option D
  4. Quick Check:

    sys.path[0] = script folder [OK]
Quick Trick: sys.path[0] is script's folder path [OK]
Common Mistakes:
  • Thinking sys.path[0] is Python install folder
  • Assuming sys.path[0] is always empty string
  • Confusing with user's home directory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes