Free PCAP-31-03 Sample Questions — Certified Associate in Python Programming

Free PCAP-31-03 sample questions for the Certified Associate in Python Programming exam. No account required: study at your own pace.

Want an interactive quiz? Take the full PCAP-31-03 practice test

Looking for more? Click here to get the full PDF with 57+ practice questions for $10 for offline study and deeper preparation.

Question 1

Which of the following lambda definitions are correct? (Choose two.)

  • A. lambda(x,y) = x//y - x%y
  • B. lambda x,y: return x//y - x%y
  • C. lambda x,y: (x,y)
  • D. lambda x,y: x//y - x%y
Show Answer
Correct Answer:
  • C. lambda x,y: (x,y)
  • D. lambda x,y: x//y - x%y
Question 2

A Python module named pymod.py contains a variable named pyvar. Which of the following snippets will let you access this variable? (Choose two.)

  • A. from pymod import pyvar pyvar ()
  • B. import pymod pymod.pyvar = 1
  • C. import pyvar from pymod pyvar = 1
  • D. from pymod import* pyvar = 1
Show Answer
Correct Answer:
  • B. import pymod pymod.pyvar = 1
  • D. from pymod import* pyvar = 1
Question 3

What is true about Object-Oriented Programming in Python? (Choose two.)

  • A. an object is a recipe for a class
  • B. the arrows on a class diagram are always directed from a superclass towards its subclass
  • C. encapsulation allows you to protect some data from uncontrolled access
  • D. inheritance is the relation between a superclass and a subclass
Show Answer
Correct Answer:
  • C. encapsulation allows you to protect some data from uncontrolled access
  • D. inheritance is the relation between a superclass and a subclass
Question 4

What is true about Python packages? (Choose two.)

  • A. a code designed to initialize a package’s state should be placed inside a file named init.py
  • B. a package’s contents can be stored and distributed as an mp3 file
  • C. __pycache__ is a folder that stores semi-compiled Python modules
  • D. the sys.path variable is a list of strings
Show Answer
Correct Answer:
  • C. __pycache__ is a folder that stores semi-compiled Python modules
  • D. the sys.path variable is a list of strings
Question 5

What is the expected output of the following code? import sys import math b1 = type(dir(math)[0]) is str b2 = type(sys.path[-1]) is str print(b1 and b2)

  • A. False
  • B. True
  • C. 0
  • D. None
Show Answer
Correct Answer:
B. True
Question 6

A Python package named pypack includes a module named pymod.py which contains a function named pyfun(). Which of the following snippets will let you invoke the function? (Choose two.)

  • A. from pypack.pymod import pyfun pyfun()
  • B. import pypack pymod.pyfun()
  • C. from pypack import * pyfun()
  • D. import pypack import pypack.pymod pypack.pymod.pyfun()
Show Answer
Correct Answer:
  • A. from pypack.pymod import pyfun pyfun()
  • D. import pypack import pypack.pymod pypack.pymod.pyfun()
Question 7

Assuming that the math module has been successfully imported, which of the following expressions evaluate to True? (Choose two.)

  • A. math.ceil(2.5) == math.trunc(2.5)
  • B. math.ceil(2.5) < math.floor(2.5)
  • C. math.floor(2.5) == math.trunc(2.5)
  • D. math.hypot(3,4) == math.sqrt(25)
Show Answer
Correct Answer:
  • C. math.floor(2.5) == math.trunc(2.5)
  • D. math.hypot(3,4) == math.sqrt(25)
Question 8

What is true about Python class constructors? (Choose two.)

  • A. the constructor is a method named __init__
  • B. there can be more than one constructor in a Python class
  • C. the constructor must return a value other than None
  • D. the constructor must have at least one parameter
Show Answer
Correct Answer:
  • A. the constructor is a method named __init__
  • D. the constructor must have at least one parameter
Question 9

What is the expected output of the following code? import sys import math b1 = type(dir(math)) is list b2 = type(sys.path) is list print(b1 and b2)

  • A. None
  • B. True
  • C. 0
  • D. False
Show Answer
Correct Answer:
B. True
Question 10

Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Choose two.) string = 'REPTILE'[:3:] string = string[-1] + string[-2::-1]

  • A. len(string) == 3
  • B. string[0] == 'E'
  • C. string[0] < string[-1]
  • D. string is None
Show Answer
Correct Answer:
  • A. len(string) == 3
  • C. string[0] < string[-1]
Question 11

Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Choose two.) string = 'python'[::2] string = string[-1] + string[-2]

  • A. len(string) == 3
  • B. string[0] == 'o'
  • C. string[0] == string[-1]
  • D. string is None
Show Answer
Correct Answer:
B. string[0] == 'o'
Question 12

What is the expected output of the following code? import sys b1 type (dir(sys)) is str b2 type (sys.path[-1]) is str print (b1 and b2)

  • A. True
  • B. False
  • C. 0
  • D. None
Show Answer
Correct Answer:
B. False
Question 13

Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Choose two.) string = 'SKY'[::-1] string = string[-1]

  • A. len(string) == 1
  • B. string[0] == 'Y'
  • C. string[0] == string[-1]
  • D. string is None
Show Answer
Correct Answer:
  • A. len(string) == 1
  • C. string[0] == string[-1]
Question 14

Which of the following expressions evaluate to True? (Choose two.)

  • A. 'in not' in 'not'
  • B. 'a' not in 'ABC'.lower()
  • C. 'not' not in 'in'
  • D. 't'.upper() in 'Thames'
Show Answer
Correct Answer:
  • C. 'not' not in 'in'
  • D. 't'.upper() in 'Thames'
Question 15

What is true about lambda functions? (Choose two.)

  • A. they are called anonymous functions
  • B. they cannot return the None value as a result
  • C. they must contain the return keyword
  • D. they must have a non-zero number of parameters
Show Answer
Correct Answer:
  • A. they are called anonymous functions
  • D. they must have a non-zero number of parameters

Aced these? Get the Full Exam

Download the complete PCAP-31-03 study bundle with 57+ questions in a single printable PDF.