Courseiva
Functions, Tuples, Dictionaries and ExceptionsmediumMultiple SelectObjective-mapped

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

Which TWO of the following are valid ways to create a dictionary with initial key-value pairs? (Select exactly 2)

⚠ Common exam trap

Python Institute often tests the distinction between the literal `{}` syntax and the `dict()` constructor, and candidates may mistakenly think that `dict()` can accept two separate lists as positional arguments, similar to how `zip()` works, or that parentheses can be used to define a dictionary.

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

d = {'a': 1, 'b': 2}

It uses the standard literal syntax for creating a dictionary with initial key-value pairs. The curly braces `{}` with colon-separated keys and values are the most common and direct way to define a dictionary in Python.

Answer analysis

Option-by-option breakdown

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

  • d = {'a': 1, 'b': 2}

    Why this is correct

    Standard dictionary literal.

  • d = ('a'=1, 'b'=2)

    Why it's wrong here

    Parentheses and assignment are not valid syntax.

  • d = dict.fromkeys(['a', 'b', 'c']) # without value

    Why it's wrong here

    Valid but creates keys with None values, not with initial pairs as given; but the stem asks for initial key-value pairs, so not suitable.

  • d = dict(a=1, b=2)

    Why this is correct

    Keyword arguments to dict() create a dictionary.

  • d = dict(['a', 'b'], [1, 2])

    Why it's wrong here

    dict() takes at most one argument; this is invalid.

About these practice questions

This PCEP question is part of Courseiva's 498-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 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.