Complete the code to import the sys module.
import [1]
The sys module provides access to variables used or maintained by the Python interpreter, including the module search path.
Complete the code to print the list of directories Python searches for modules.
import sys print(sys.[1])
sys.modules which is a dictionary of loaded modules, not paths.sys.path is a list of strings that specifies the search path for modules.
Fix the error in the code to add a new directory to the module search path.
import sys sys.path.[1]('/my/custom/path')
add which is not a list method.extend which expects an iterable, not a single string.The append method adds an item to the end of the list sys.path.
Fill both blanks to insert a directory at the start of the module search path.
import sys sys.path.[1](0, [2])
append instead of insert to add at the start.The insert method adds an item at a specific position in the list. Position 0 means the start. The directory string must be the path you want to add.
Fill all three blanks to create a new list of directories from sys.path that contain 'site-packages'.
import sys site_dirs = [p[1] for p in sys.[2] if 'site-packages' [3] p]
if instead of in for substring check.The list comprehension iterates over sys.path and selects paths containing 'site-packages' using the in keyword.