PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 123


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

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

Show Answer
Correct Answer: C

C

Discussion

8 comments
Sign in to comment
macxszOption: A
Apr 30, 2022

Only correct is: A. import pymod pymod.pyvar = 1

Dav023
Sep 29, 2022

All options ar incorrect. Use this snippets to test them from math import pi print(pi)

rotimislawOption: A
Nov 15, 2022

A. import pymod pymod.pyvar = 1 Correct B. import pyvar from pymod pyvar = 1 Incorrect C. from pymod import pyvar pyvar() Incorrect D. from pyfun import * pyvar = 1 Incorrect There's another option to A. presented above, but neither B nor C meets it in full: from pymod import pyvar #see the order of 'from' and 'import' pyvar = 1 #no '()' after pyvar variable name

NengggOption: A
Dec 11, 2022

A is correct

DezzoPalYeahOption: A
Oct 10, 2023

Answer is A,C

temorOption: A
Jan 21, 2024

A. import pymod followed by pymod.pyvar = 1: This approach imports the module pymod and then accesses the variable pyvar as an attribute of the module. C. from pymod import pyvar: This approach directly imports the pyvar variable from the pymod module, making it accessible without referencing the module name. The other options are incorrect: B. import pyvar from pymod is not valid syntax for importing a variable. You should use from pymod import pyvar to import the variable correctly. D. from pyfun import * pyvar = 1 is attempting to import all functions and variables from a module named pyfun, which is not mentioned in the question. It's unrelated to the pymod module and pyvar variable. So, options A and C are the correct ways to access the pyvar variable from the pymod.py module.

Damon54Options: AC
Feb 9, 2024

A e C correct

zantrzOption: D
Feb 12, 2024

In my opinion there is a typo mistake. In answer D there should be: D. from pymod import * pyvar = 1 The correct two answers would be be A and D. I think that C cannot work due to =(). C. from pymod import pyvar; pyvar() This imports the variable pyvar directly from the module pymod and assigns it to the local namespace. Then, it tries to call pyvar as a function, which may raise a TypeError depending on the content of pyvar.