PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Easy

Question 15

Q446 - Modules


The module has been imported using the following line.


from mod import func


How can you invoke the function?


  • A

    func()

  • B

    mod::func()

  • C

    mod.func()

  • D

    mod:func()

Reveal correct answer

Correct answer: A

Explanation

Topics: from import

Try it yourself:

Explanation:

Only the function func() of the module mod gets imported here.

To invoke the function you just need the function name: func()

(There is another question about this topic Q240.)


Q446 (Please refer to this number, if you want to write me about this question.)

A. By using the syntax func(), you can directly invoke the function that has been imported from the module. This is the correct way to call the function after importing it using the specified syntax.

B. The syntax mod::func() is incorrect as the double colon (::) is not a valid operator for calling functions in Python. This syntax is not recognized by Python, and attempting to use it to invoke the function would result in a syntax error.

C. The syntax mod.func() is incorrect in this context because the function has been imported directly as func, not as a method of the mod module. Using this syntax would result in a 'NameError' as the function is not accessed through the module.

D. The syntax mod:func() is incorrect as the colon (:) is not used to call functions in Python. This syntax is not valid for invoking functions, and using it would result in a syntax error.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need