PCAP : Certified Associate in Python Programming : Part 04
-
What is the expected output of the following code?
- 21
- 12
- 3
- none
-
A method for passing the arguments used by the following snippet is called:
- sequential
- named
- positional
- keyword
-
What is the expected behavior of the following code?
It will
- print 2 1
- print 1 2
- cause a runtime exception
- print <
generator object f at (some hex digits)
>
Explanation:
-
What is the expected output of the following code?
- 2
- The code will cause a runtime exception
- 1
- 3
-
What is the expected behavior of the following code?
It will:
- print 0
- cause a runtime exception
- prints 3
- print an empty line
-
If any of a class’s components has a name that starts with two underscores (___), then:
- the class component’s name will be mangled
- the class component has to be an instance variable
- the class component has to be a class variable
- the class component has to be a method
Explanation:Reference: https://hackernoon.com/understanding-the-underscore-of-python-309d1a029edc -
If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:
- except Ex1 Ex2:
- except (ex1, Ex2):
- except Ex1, Ex2:
- except Ex1+Ex2:
Explanation:Reference: https://www.programiz.com/python-programming/exception-handling -
A function called issubclass (c1, c2) is able to check if:
- c1 and c2 are both subclasses of the same superclass
- c2 is a subclass of c1
- c1 is a subclass of c2
- c1 and c2 are not subclasses of the same superclass
Explanation:Reference: https://www.oreilly.com/library/view/python-in-a/9781491913833/ch04.html -
A class constructor (Choose two.)
- can return a value
- cannot be invoked directly from inside the class
- can be invoked directly from any of the subclasses
- can be invoked directly from any of the superclasses
-
The following class definition is given. We want the show () method to invoke the get () method, and then output the value the get () method returns. Which of the invocations should be used instead of XXX?
- print (get(self))
- print (self.get())
- print (get())
- print (self.get (val))
-
If S is a stream open for reading, what do you expect from the following invocation?
- one line of the file will be read and stored in the string called C
- the whole file content will be read and stored in the string called C
- one character will be read and stored in the string called C
- one disk sector (512 bytes) will be read and stored in the string called C
-
You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Choose two.)
-
data = bytearray (16) bf.readinto (data)
-
data = binfile.read (bytearray (16))
-
bf. readinto (data = bytearray (16))
-
data = bytearray (binfile.read (16))
Explanation:Reference: https://www.devdungeon.com/content/working-binary-data-python -
-
What is the expected output of the following snippet?
-
True False
-
True True
-
False False
-
False True
-
-
Assuming that the code below has been executed successfully, which of the following expressions will always evaluate to True? (Choose two.)
-
v1 >= 1
-
v1 == v2
-
len(random.sample([1,2,3],2)) > 2
-
random.choice([1,2,3]) >=1
-
-
Which one of the platform module functions should be used to determine the underlying platform name?
-
platform.python_version()
-
platform.processor()
-
platform.platform()
-
platform.uname()
-
-
What is the expected output of the following code?
-
False
-
None
-
True
-
0
-
-
With regards to the directory structure below, select the proper forms of the directives in order to import module_a. (Choose two.)
-
from pypack import mpdule_a
-
import module_a from pypack
-
import module_a
-
import pypack.module_a
-
-
A Python module named pymod.py contains a function named pyfun().
Which of the following snippets will let you invoke the function? (Choose two.)
-
import pymod pymod.pyfun()
-
from pymod import pyfun pyfun()
-
from pymod import * pymod.pyfun()
-
import pyfun from pymod pyfun()
Explanation:Reference: https://www.tutorialsteacher.com/python/python-module -
-
What is true about Python packages? (Choose two.)
- a package is a single file whose name ends with the pa extension
- a package is a group of related modules
- the __name__ variable always contains the name of a package
- the pyc extension is used to mark semi-compiled Python packages
Explanation:Reference: https://docs.python.org/3/tutorial/modules.html -
What is the expected behavior of the following code?
- it outputs 3
- it outputs 1
- the code is erroneous and it will not execute
- it outputs 2
Explanation:
Subscribe
0 Comments
Newest