Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer is working with a dictionary `config = {'host': 'localhost', 'port': 8080}`. They need to perform operations that modify or access the dictionary without causing errors. Which two of the following operations are valid and will not raise an exception? (Choose two.)

⚠ Common exam trap

Watch out — candidates often confuse dictionary methods with list methods or assuming that bracket access is safe for missing keys, leading to incorrect selections.

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

✓

`config.get('timeout')`

The `get` method safely retrieves a value without raising an exception if the key is missing, returning None. Assigning to an existing key simply updates the value. Both are valid operations that do not cause errors, unlike bracket access for missing keys, `pop` without default, or using a non-existent method.

Answer analysis

Option-by-option breakdown

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

  • ✗

    `config.remove('host')`

    Why it's wrong here

    Dictionaries do not have a `remove` method; that method is for lists. Attempting to call `config.remove` will raise an AttributeError. To remove a key from a dictionary, you would use `pop` or `del`. Thus, this operation is invalid.

  • ✗

    `config['timeout']`

    Why it's wrong here

    Accessing a key that does not exist in a dictionary using square brackets raises a KeyError. Since 'timeout' is not in the dictionary, this operation will raise an exception. It is not a safe way to access a possibly missing key.

  • ✗

    `config.pop('timeout')`

    Why it's wrong here

    The `pop` method removes the specified key and returns its value. If the key is not found, it raises a KeyError unless a default value is provided. Since 'timeout' is not in the dictionary, this operation will raise an exception.

  • ✓

    `config.get('timeout')`

    Why this is correct

    The `get` method returns None if the key is not found, without raising an exception. It is a safe way to access a key that may not exist. In this case, 'timeout' is not present, so it returns None. This operation is valid and will not raise an error.

  • ✓

    `config['port'] = 9090`

    Why this is correct

    Assigning a value to an existing key updates the value associated with that key. Since 'port' already exists in the dictionary, this operation simply changes its value to 9090. It does not raise an exception; it is a valid modification.

About these practice questions

This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

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.