Question 15 of 498
PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer needs to store the result of dividing two numbers, a/b, but only if b is not zero. They write: result = a / b if b != 0 else 'undefined'. What is the data type of result when b is zero?
⚠ Common exam trap
Python Institute often tests the ternary conditional expression to see if candidates mistakenly think the else branch returns a special 'undefined' value (like in JavaScript) instead of recognizing it as a plain Python string literal.
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
✓
str
When `b` is zero, the expression `a / b if b != 0 else 'undefined'` evaluates to the string literal `'undefined'`. Therefore, the variable `result` is assigned a value of type `str` (string). The conditional expression explicitly returns a string in the else branch, making option D correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
float
Why it's wrong here
When b is 0, result is assigned 'undefined', which is a string.
- ✗
NoneType
Why it's wrong here
None is not returned; the string 'undefined' is returned.
- ✗
bool
Why it's wrong here
No boolean value is involved.
- ✓
str
Why this is correct
The else clause returns a string literal, so result is a string.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.