Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

Which TWO of the following are valid dictionary methods? (Select two.)

⚠ Common exam trap

The exam often tests candidates by including method names from other languages (like Java's `keyset()` or `entries()`) to exploit confusion between Python and Java dictionary APIs.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

keys()

The `keys()` method returns a view object displaying all keys in a dictionary, and `values()` returns a view object of all values. Both are built-in dictionary methods in Python, making them valid for the PCEP exam.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    keys()

    Why this is correct

    keys() returns a view object of the dictionary's keys and is a genuine built-in dict method. It satisfies the question's requirement for a valid dictionary method, distinguishing it from list-only operations such as append or index.

  • ✗

    keyset()

    Why it's wrong here

    Python dictionaries expose keys(), not keyset(); the method name simply does not exist, so calling it raises AttributeError. It tempts because Java's Map interface offers keySet(), and candidates familiar with Java may assume Python mirrors that naming convention.

  • ✗

    entries()

    Why it's wrong here

    Python dictionaries provide items(), not entries(); entries() is undefined and raises AttributeError at runtime. The name tempts because Java's Map exposes entrySet() and JavaScript's Object.entries() returns key-value pairs, so the concept feels familiar despite the wrong identifier.

  • ✗

    pairs()

    Why it's wrong here

    No pairs() method exists on Python dictionaries; iteration over key-value tuples is done via items(), so pairs() raises AttributeError. It tempts because the name describes what items() returns, and similar pair-oriented helpers appear in other languages and libraries.

  • ✓

    values()

    Why this is correct

    values() returns a view of the dictionary's values, and it is a genuine built-in dict method. It satisfies the question's requirement for a valid dictionary method, unlike functions such as append or insert that belong to lists.

About these practice questions

One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.