Exam PCAP All QuestionsBrowse all questions from this 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.)

    Correct Answer: A, C

    C

Discussion
macxszOption: A

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

zantrzOption: D

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.

Damon54Options: AC

A e C correct

temorOption: A

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.

DezzoPalYeahOption: A

Answer is A,C

NengggOption: A

A is correct

rotimislawOption: A

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

Dav023

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