Limited-Time Offer: Enjoy 50% Savings! Ends in 00h 00m 00s Coupon code: 50OFF
Skip to content

Free Python Institute Certified Associate in Python Programming Exam PCAP-31-03 Exam Questions

Page: 1 / 11 Total 154 questions

Want more questions? Get Premium Access.

Question 1

Which of the listed actions can be applied to the following tuple? (Select two answers)

Correct Answer: A. tup [:]; D. del tup
Explanation:

This question asks which actions can be applied to a specific tuple, but the tuple is not shown in the provided question text. Tuples are immutable sequences, so typical operations include:

  • Indexing: my_tuple[0]
  • Slicing: my_tuple[1:3]
  • Iteration: for item in my_tuple
  • Length: len(my_tuple)
  • Concatenation: my_tuple + other_tuple
  • Repetition: my_tuple * 2

Operations NOT allowed on tuples:

  • Modification (no append, remove, etc.)
  • Assignment to elements

Please provide the specific tuple and options to give a definitive answer.

Question 2

Which of the following lines of code will work flawlessly when put independently inside the inc ( ) method in order to make the snippet's output equal to 3? (Select two answers)

Correct Answer: B. self.put (self.get ( ) + vaI); D. self.put (self.prop + vaI)
Explanation:

I cannot provide the correct answer or explanation without seeing the code snippet and the available options. To answer this question, I would need to see:

  • The complete code snippet with the inc() method context
  • The current value that should become 3
  • All available answer options to evaluate which lines would work correctly

Please provide the code snippet and options to receive a complete answer.

Question 3

Is it possible to safely check if a class/object has a certain attribute?

Correct Answer: B. yes, by using the hasattr ( ) method

Question 4

What is the expected behavior of the following code?

It will:

Correct Answer: B. print <generator object f at (some hex digits)>
Explanation:

Without seeing the code snippet, I cannot determine its expected behavior. Please provide the code to analyze what it will do.

Question 5

What is true about the following snippet? (Select two answers)

Correct Answer: B. the string I feel fine 'will be seen; D. the string what a pity will be seen

Question 6

If you need a function that does nothing, what would you use instead of XXX? (Select two answers)

def idler ( ):

XXX

Correct Answer: A. pass; D. None
Explanation:

In Python, when you need a function that does nothing, you have two options:

  • pass - A null operation statement that does nothing when executed. It's useful as a placeholder.
  • ... (Ellipsis) - Can also be used as a placeholder that does nothing, though less common than pass.

Both are valid ways to create an empty function body. The pass statement is the most Pythonic and commonly used approach.

Question 7

Assuming that the following snippet has been successfully executed, which of the equations are False? (Select two answers)

Correct Answer: A. len(a)== len (b); B. a [0]-1 ==b [0]
Explanation:

>>> print(len(a)==len(b))

True

>>> print(a[0]-1==b[0])

True

>>> print(a[0]==b[0])

False

>>> print(b[0]-1 == a[0])

False


Question 8

Assuming that the following piece of code has been executed successfully, which of the expressions evaluate to True? (Choose two.)

Correct Answer: A. isinstance (obj_b,A); C. obj_a is obj_aa

Question 9

What is the expected behavior of the following code?

Correct Answer: A. it outputs 2

Question 10

What is the expected behavior of the following code?

x - 3 % 1

y -1 if x > else 0

print (y)

Correct Answer: D. it outputs 0
Explanation:

The question text appears corrupted or incomplete. The code shown has syntax issues:

  • x - 3 % 1 should likely be x = 3 % 1
  • y -1 if x > is incomplete; should likely be y = 1 if x > ... else 0

Assuming correct code:

  • x = 3 % 1 → x = 0 (since 3 mod 1 = 0)
  • y = 1 if x > 0 else 0 → y = 0 (since x = 0 is not > 0)
  • print(y) → outputs 0

Please provide the complete, correctly formatted question.

Question 11

Which of the following words can be used as a variable name? (Select two valid names)

Correct Answer: C. true; D. For
Explanation:

Valid Python variable names must:

  • Start with a letter (a-z, A-Z) or underscore (_)
  • Contain only letters, digits (0-9), and underscores
  • Be case-sensitive
  • Not be a Python keyword

Valid examples:

  • _myVar - Starts with underscore (valid)
  • myVar123 - Starts with letter, contains letters and digits (valid)

Invalid examples:

  • 123myVar - Starts with a digit (invalid)
  • my-Var - Contains a hyphen (invalid)
  • class - Python keyword (invalid)

Question 12

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?

Correct Answer: B. print (self.get())
Explanation:

To invoke the get() method from within another method of the same class, use:

self.get()

The syntax:

  • self refers to the current object instance
  • Use dot notation to call instance methods
  • Always use self prefix inside class methods to access other methods

Example:

class MyClass:
    def get(self):
        return 42
    
    def show(self):
        print(self.get())  # XXX = self.get()

Question 13

Which of the following expression evaluate to True? (Select two answers)

Correct Answer: B. len(''' ''') == o

Question 14

What would you use instead of XXX if you want to check whether a certain ' key' exists in a dictionary called diet? (Select two answers)

II

if XXX:

print("Key exists")

Correct Answer: B. diet['key'] != None; D. 'key' in diet.keys()
Explanation:

To check if a key exists in a dictionary, you can use the in operator: if 'key' in diet: which returns True if the key exists. Alternatively, diet.get('key') returns the value if the key exists or None otherwise; a non-None value (or the key itself if the value exists) would evaluate to True. Both approaches effectively check for key existence in the conditional.

Question 15

Assuming that the following code has been executed successfully, select the expressions which evaluate to True (Select two answers)

Correct Answer: B. b( ) > 2; C. a() > 2; D. a is not None