Sign in
Home/Python Institute/Certified Entry-Level Python Programmer (PCEP-30-02)/Free questions

Certified Entry-Level Python Programmer (PCEP-30-02) — Free Practice Questions

10 free sample questions from a bank of 396, with the correct answers and explanations. No signup required — start practising right now.

1Insert the correct snippet so that the program produces the expected output. Expected output: Code:
Certified Entry-Level Python Programmer (PCEP-30-02) question 1Certified Entry-Level Python Programmer (PCEP-30-02) question 1
  • b = 0 not in list
  • b = list[0]
  • b = 0 in list
  • b = False
Answer: C

The short version

C — C produces the expected truthy membership result correctly. membership test with in returns True for zero in list. With a list containing False, the expression 0 in list evaluates membership by equality, and since 0 equals False in Python, the test returns True.

Key concepts in this question

  • Membership operator: The in operator tests whether a value equals any element, returning a boolean rather than the element itself.
  • Equality nuance: Zero equals False in Python numeric comparison, so 0 is considered present when False is stored.
  • Assignment effect: Storing the boolean result in b gives True, matching the expected output trace.

Why C is correct

With a list containing False, the expression 0 in list evaluates membership by equality, and since 0 equals False in Python, the test returns True. Assigning that result to b therefore yields True as expected. Using not in would invert to False, list indexing would fetch an element rather than test membership, and assigning False directly ignores the list, so the settled key follows equality plus membership semantics.

Why the others are wrong

  • A. uses 0 not in list, which negates the membership test and would assign False instead of True.
  • B. indexes list position zero, which returns the element False rather than performing a membership comparison.
  • D. assigns False directly, bypassing any list evaluation and missing the membership logic under test.

PCEP-30-02 exam tip

Link in list plus zero and False to True via equality for membership traps.

2What will be the output of the following code snippet?
Certified Entry-Level Python Programmer (PCEP-30-02) question 2
  • 3
  • 2
  • 4
  • 1
Answer: C

The short version

C — C sums dictionary values to 4 correctly. distinct int and string keys sum to 4. The dictionary starts empty, then integer key 1 maps to 1 and string key 1 maps to 2 as separate entries because int and str hash differently.

Key concepts in this question

  • Key typing: Integer 1 and string 1 are distinct dictionary keys with separate slots despite similar appearance.
  • Mutation order: Increment applies only to the integer-key entry, raising it from 1 to 2 before summation.
  • Summation scope: Looping over the map adds each stored value once, giving 2 plus 2 equals 4.

Why C is correct

The dictionary starts empty, then integer key 1 maps to 1 and string key 1 maps to 2 as separate entries because int and str hash differently. Incrementing integer key 1 makes its value 2, so the map holds 2 plus 2. Summing over values therefore gives 4, which the settled key reports. Treating the two key types as one entry would miscount the total.

Why the others are wrong

  • A. gives 3, which would require values such as 1 plus 2 without the increment step being applied.
  • B. gives 2, which counts only one entry and ignores that int and str keys coexist.
  • D. gives 1, which reflects a single initial value rather than the final two-entry total.

PCEP-30-02 exam tip

Split int versus str keys first whenever a dict mixes 1 and quoted 1.

3What is the output of the following snippet?
Certified Entry-Level Python Programmer (PCEP-30-02) question 3
  • two
  • one
  • (‘one’, ‘two’, ‘three’)
  • three
Answer: A

The short version

A — A traces cyclic lookups to two correctly. three-step dictionary chaining cycles back to two. Starting from value two via key one, each iteration replaces v with the value mapped from current v, cycling through three to one to two across three steps.

Key concepts in this question

  • Chained lookup: Each step uses the prior result as the next key, walking a directed cycle inside the map.
  • Cycle length: Three entries form a 3-cycle, so three moves from any start return to the start value.
  • Print timing: Output reflects the value after the loop completes, not intermediate keys.

Why A is correct

Starting from value two via key one, each iteration replaces v with the value mapped from current v, cycling through three to one to two across three steps. After exactly three lookups the walk returns to two, so printing v shows two. The settled key therefore follows chained dictionary dereferencing rather than tuple or single-step logic.

Why the others are wrong

  • B. gives one, which is the value after two steps rather than after the full three-iteration cycle.
  • C. gives the whole tuple of keys, confusing the container display with the walked scalar result.
  • D. gives three, which is the value after one step rather than after three steps.

PCEP-30-02 exam tip

Count lookup steps modulo cycle length to land on the final walked value.

4What is the expected output of the following code?
Certified Entry-Level Python Programmer (PCEP-30-02) question 4
  • [3, 1, 25, 5, 20, 5, 4]
  • [1, 3, 4, 5, 20, 5, 25]
  • [3, 5, 20, 5, 25, 1, 3]
  • [1, 3, 3, 4, 5, 5, 20, 25]
  • [3, 4, 5, 20, 5, 25, 1, 3]
Answer: C

The short version

C — C shows post-pop list without 4 correctly. pop at index 1 removes 4 leaving the settled list. Starting from 3, 4, 5, 20, 5, 25, 1, 3, calling pop with index 1 removes the second element, namely 4, and shifts later items left.

Key concepts in this question

  • Pop index: Pop with an index removes that position and returns it, mutating the original list in place.
  • Shift effect: Elements after the removed slot move left, preserving order of the survivors.
  • Print target: Printing after mutation shows the shortened list, not the popped value alone.

Why C is correct

Starting from 3, 4, 5, 20, 5, 25, 1, 3, calling pop with index 1 removes the second element, namely 4, and shifts later items left. Printing the mutated list therefore shows 3, 5, 20, 5, 25, 1, 3. Other options either keep 4, reorder, or duplicate values inconsistently with pop semantics, so the settled key follows list mutation rules.

Why the others are wrong

  • A. keeps a scrambled order with 25 early, which does not result from removing index 1 from the given start.
  • B. shows a sorted order, but pop never sorts, it only removes one position.
  • D. retains duplicate 3 and 4 patterns inconsistent with single removal of 4.
  • E. retains 4, indicating no removal happened, contradicting the pop call.

PCEP-30-02 exam tip

Cross out index 1 on paper before predicting any pop result.

5Which of the following sentences is true?
Certified Entry-Level Python Programmer (PCEP-30-02) question 5
  • str1 and str2 are different (but equal) strings.
  • str1 and str2 are different names of the same strings.
  • str1 is longer than str2
  • str2 is longer than str1
Answer: A

The short version

A — A distinguishes equal versus identical strings correctly. slice copy creates equal but distinct string object. Slicing the full string with empty bounds builds a new string object with the same characters, so str1 and str2 compare equal in value while residing at different identities.

Key concepts in this question

  • Value equality: Double-equals compares character content, which matches for two copies of Peter.
  • Identity split: Separate objects can share content after slicing, so is may be False while equality is True.
  • Length stability: Copying the whole slice preserves length, ruling out longer or shorter claims.

Why A is correct

Slicing the full string with empty bounds builds a new string object with the same characters, so str1 and str2 compare equal in value while residing at different identities. They are therefore different but equal strings. Calling them the same object overstates identity, and length claims fail because both hold Peter, so the settled key follows value versus identity semantics.

Why the others are wrong

  • B. claims different names for the same object, which would imply shared identity rather than copied equality.
  • C. claims str1 longer, but both hold five characters after a full slice.
  • D. claims str2 longer, which likewise contradicts identical copied content.

PCEP-30-02 exam tip

Translate slicing copy to equal but not identical for string questions.

6The fact that tuples belong to sequence types means:
  • they can be modified using the del instruction
  • they can be extended using the .append() method
  • they are actually lists
  • they can be indexed and sliced like lists
Answer: D

The short version

D — D interprets sequence typing correctly. sequence membership means indexing plus slicing support. Belonging to sequence types means supporting ordered access via indices and slices, which tuples share with lists and strings despite immutability.

Key concepts in this question

  • Sequence protocol: Sequences define length, indexing, slicing, and iteration in a fixed order.
  • Immutability boundary: Tuples implement the read side of sequences while blocking write operations like append or delete.
  • Type separation: Sharing sequence behaviour does not make tuples become lists; mutability still differs.

Why D is correct

Belonging to sequence types means supporting ordered access via indices and slices, which tuples share with lists and strings despite immutability. Deletion, append, and list identity contradict tuple immutability and type distinctions. The settled key therefore follows the sequence protocol definition that emphasizes positional access rather than mutation.

Why the others are wrong

  • A. allows del modification, which violates tuple immutability even though sequences support indexing.
  • B. allows append extension, which is a mutable-list method unavailable on tuples.
  • C. claims tuples are lists, collapsing distinct types that differ on mutability.

PCEP-30-02 exam tip

Hear sequence types and answer indexed and sliced like lists.

7What is the output of the following code?
Certified Entry-Level Python Programmer (PCEP-30-02) question 7
  • [1, 1, 1]
  • [3, -1, 1]
  • [3, 1, 1]
Answer: C

The short version

C — C evaluates negative-index assignment correctly. negative-index assignment copies middle value to end. With 3, 1, minus 1, assigning element at minus 1 from element at minus 2 copies the middle 1 over the trailing minus 1.

Key concepts in this question

  • Negative indices: Minus 1 addresses the last slot and minus 2 the one before it, without reversing the list.
  • Assignment direction: Right-hand value is read before the left-hand slot is overwritten, so the middle 1 propagates.
  • In-place update: The operation mutates the existing list rather than creating a new one.

Why C is correct

With 3, 1, minus 1, assigning element at minus 1 from element at minus 2 copies the middle 1 over the trailing minus 1. The list becomes 3, 1, 1, which printing shows. Alternatives that change the first element or leave minus 1 unchanged ignore the targeted last-position write, so the settled key follows negative-index semantics.

Why the others are wrong

  • A. gives all ones, which would require also overwriting the first element that the statement never touches.
  • B. keeps minus 1 at the end, indicating no assignment occurred despite the explicit write.

PCEP-30-02 exam tip

Rewrite minus indices as positive positions before simulating the write.

8Assuming that the tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:
Certified Entry-Level Python Programmer (PCEP-30-02) question 8
  • is illegal
  • may be illegal if the tuple contains strings
  • can be executed if and only if the tuple contains at least two elements
  • is fully correct
Answer: A

The short version

A — A flags tuple item assignment as illegal correctly. item assignment on immutable tuple raises error. Tuples are immutable, so any instruction that assigns to an indexed position must fail with a TypeError rather than updating in place.

Key concepts in this question

  • Immutability guarantee: Once created, tuple slots cannot be rebound, preserving hashability and structural integrity.
  • Error type: Item assignment raises TypeError, signalling an unsupported operation rather than a value problem.
  • No conditional pass: No element count or content mix makes indexed assignment valid on a true tuple.

Why A is correct

Tuples are immutable, so any instruction that assigns to an indexed position must fail with a TypeError rather than updating in place. Content type, length, or string presence does not lift immutability. The settled key therefore marks the attempt illegal unconditionally.

Why the others are wrong

  • B. conditions illegality on string content, but immutability applies regardless of element types.
  • C. requires at least two elements, yet even longer tuples reject item assignment.
  • D. claims fully correct execution, contradicting the core immutable contract.

PCEP-30-02 exam tip

See tuple plus indexed assignment and answer illegal immediately.

9A data structure described as LIFO is actually a:
  • stack
  • tree
  • list
  • heap
Answer: A

The short version

A — A maps LIFO to stack correctly. LIFO discipline defines a stack. Last-in-first-out means the most recently added item is removed first, which is exactly stack push and pop behaviour.

Key concepts in this question

  • Stack operations: Push adds to the top and pop removes from the top, enforcing LIFO order.
  • Discipline contrast: FIFO queues, priority heaps, and trees each impose different removal orders.
  • Use fit: Call stacks and undo histories rely on LIFO so the latest context unwinds first.

Why A is correct

Last-in-first-out means the most recently added item is removed first, which is exactly stack push and pop behaviour. Trees organize hierarchically, generic lists allow both ends, and heaps order by priority rather than arrival recency. The settled key therefore follows data-structure discipline mapping. In implementation use list append plus pop for a simple stack, or deque when both ends are needed.In service operation this distinction guides triage, routing, and audit evidence, so applying the settled rule consistently reduces rework and failed reviews.

Why the others are wrong

  • B. names tree, which structures parent-child branches rather than arrival-order removal.
  • C. names list generically, which can implement many disciplines but does not specifically denote LIFO.
  • D. names heap, which removes by priority key rather than by most-recent arrival.

PCEP-30-02 exam tip

Pair LIFO with stack and FIFO with queue as an instant split.

10How would you remove all the items from the d dictionary? Expected output: Code:
Certified Entry-Level Python Programmer (PCEP-30-02) question 10Certified Entry-Level Python Programmer (PCEP-30-02) question 10
  • d.del()
  • d.remove()
  • del d
  • d.clear()
Answer: D

The short version

D — D clears dictionary contents correctly. clear empties the dict while keeping the object alive. Calling clear on d removes all key-value pairs but leaves d defined as an empty dict, matching the remove-all-items goal.

Key concepts in this question

  • Clear effect: Clear mutates in place to empty while preserving identity and references to the same object.
  • Delete distinction: Del removes the variable binding, so later use raises NameError instead of showing empty.
  • Method existence: Dicts expose clear, not remove or del methods, making only clear callable.

Why D is correct

Calling clear on d removes all key-value pairs but leaves d defined as an empty dict, matching the remove-all-items goal. Del without parentheses is invalid, remove does not exist for dicts, and bare del deletes the name binding itself. The settled key therefore follows dict-method semantics. In cleanup call clear when other references must see the same now-empty dict, otherwise rebind to a new empty literal.In service operation this distinction guides triage, routing, and audit evidence, so applying the settled rule consistently reduces rework and failed reviews.

Why the others are wrong

  • A. calls d dot del, which is not a dict method and raises AttributeError.
  • B. calls d dot remove, which is a list method and does not exist for dictionaries.
  • C. uses del d, which unbinds the name rather than emptying the container.

PCEP-30-02 exam tip

Need empty but alive dict, choose clear, need gone entirely, choose del.

Want the full bank of 396 questions for Certified Entry-Level Python Programmer (PCEP-30-02)? See all practice exams.