Certified Associate in Python Programming (PCAP-31-03) — Question 108
A Python module named pymod.py contains a variable named pyvar. Which of the following snippets will let you access this variable? (Choose two.)
Answer options
- A. from pymod import pyvar pyvar ()
- B. import pymod pymod.pyvar = 1
- C. import pyvar from pymod pyvar = 1
- D. from pymod import* pyvar = 1
Correct answer: A, D
Explanation
Option A is correct as it directly imports the variable pyvar from the pymod module. Option D is also correct because it imports all variables from pymod, making pyvar accessible. Options B and C are incorrect because they do not properly access pyvar; B attempts to assign a value to it, while C uses incorrect syntax for importing.