exam questions

Exam PCAP-31-03 All Questions

View all questions & answers for the PCAP-31-03 exam

Exam PCAP-31-03 topic 1 question 87 discussion

Actual exam question from Python Institute's PCAP-31-03
Question #: 87
Topic #: 1
[All PCAP-31-03 Questions]

Python module named pymod.py contains a variable named pyvar.

Which of the following snippets will let you access the variable? (Choose two.)

  • A. from pymod import *
    pyvar = 1
  • B. import pyvar from pymod
    pyvar = 1
  • C. from pymod import pyvar
    pyvar()
  • D. import pymod
    pymod.pyvar = 1
Show Suggested Answer Hide Answer
Suggested Answer: AD 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
flthymcnsty
1 month ago
Selected Answer: AD
Explanation: The correct answers are: A: from pymod import * pyvar = 1 from pymod import * imports all names (variables, functions, etc.) defined in the pymod module into the current namespace, including pyvar. After importing, you can access or modify pyvar directly. Note: Overwriting pyvar with pyvar = 1 will replace its value with 1 in the current namespace. D: import pymod pymod. pyvar = 1 import pymod imports the entire pymod module. You can then access pyvar as pymod.pyvar. Assigning pymod.pyvar = 1 modifies the value of pyvar within the pymod module’s namespace.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago