Browse Python Institute Certification Guides

Python Institute PCEP Sample Questions with Explanations

Python Institute PCEP sample questions with explanations, traps, topic labels, and IT Mastery route links.

These original sample questions are designed to help you check how the exam topics appear in decision-style prompts. They are not taken from the live exam.

Use these sample questions as a guided self-assessment for Certified Entry-Level Python Programmer (PCEP) topics such as variables, types, operators, control flow, loops, functions, scope, exceptions, strings, lists, tuples, dictionaries, and basic object concepts. The prompts focus on tracing execution accurately.

Where these questions fit in the PCEP guide

The sample set below is part of the Python Institute PCEP guide path:

PCEP Python execution sample questions

Work through each prompt before opening the explanation. PCEP questions often test exact values, types, scope, mutation, and exceptions rather than broad definitions.


Question 1

Topic: List mutation versus rebinding

What is printed by this code?

1items = [1, 2]
2alias = items
3items += [3]
4items = items + [4]
5print(alias)
  • A. [1, 2]
  • B. [1, 2, 3]
  • C. [1, 2, 3, 4]
  • D. The code raises a TypeError.

Best answer: B

Explanation: alias and items initially refer to the same list. items += [3] mutates that list in place. Then items = items + [4] creates a new list and rebinds items, leaving alias pointing to the list that contains [1, 2, 3].

Why the other choices are weaker:

  • A ignores the in-place mutation from +=.
  • C assumes the later rebinding also changes alias.
  • D is wrong because list concatenation is valid in both operations.

What this tests: Object identity, list mutation, and variable rebinding.

Related topics: Lists; Mutation; Aliasing; Rebinding


Question 2

Topic: Loop else behavior

What is printed by this code?

1for n in [2, 4, 6]:
2    if n % 2:
3        print("odd")
4        break
5else:
6    print("done")
  • A. odd
  • B. odd and then done
  • C. done
  • D. Nothing is printed.

Best answer: C

Explanation: The if condition is false for every even number, so the loop never executes break. A loop else block runs when the loop completes normally.

Why the other choices are weaker:

  • A assumes one number is odd, but all values are even.
  • B would require both a printed odd value and normal completion, which cannot happen with the break.
  • D ignores the loop else block.

What this tests: Loop completion, break, truthiness of modulo results, and loop else.

Related topics: Loops; else; break; Modulo


Question 3

Topic: Default argument state

What is printed by this code?

1def add(value, bucket=[]):
2    bucket.append(value)
3    return bucket
4
5print(add(1))
6print(add(2))
  • A. [1] and then [2]
  • B. [] and then []
  • C. The function does not compile because list defaults are forbidden.
  • D. [1] and then [1, 2]

Best answer: D

Explanation: Default argument objects are created when the function is defined, not each time it is called. Both calls use the same list because no second argument is supplied.

Why the other choices are weaker:

  • A assumes a fresh list is created for every call.
  • B ignores that append mutates the list.
  • C is wrong because mutable defaults are legal, even though often risky.

What this tests: Function defaults, list mutation, and call-time versus definition-time behavior.

Related topics: Functions; Default arguments; Lists; State


Question 4

Topic: Dictionary lookup and exceptions

What is printed by this code?

1data = {"a": 1, "b": 2}
2try:
3    print(data["c"])
4except KeyError:
5    print(data.get("c", 0))
  • A. 0
  • B. None
  • C. KeyError
  • D. 1

Best answer: A

Explanation: Indexing a missing key with data["c"] raises KeyError. The handler then uses get("c", 0), which returns the provided default value 0.

Why the other choices are weaker:

  • B would be the result of data.get("c") without an explicit default.
  • C ignores that the exception is caught.
  • D is the value for key "a", not key "c".

What this tests: Dictionary indexing, get, default values, and exception handling flow.

Related topics: Dictionaries; KeyError; get; Exceptions

Independent study note

Tech Exam Lexicon and IT Mastery are independent study tools. They are not affiliated with, endorsed by, or sponsored by Python Institute or any certification body.

Revised on Sunday, May 10, 2026