PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A beginner writes: x = 10; y = "20"; print(x + y). What will happen?
⚠ Common exam trap
Python Institute often tests the misconception that Python will automatically convert types (like JavaScript does) or that `+` always concatenates, leading candidates to pick options A or B instead of recognizing the strict type-checking that raises a `TypeError`.
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
✓
It raises a TypeError
Python does not allow implicit type conversion between a string and an integer in an addition operation. The `+` operator with a string and an integer raises a `TypeError`, as Python's dynamic typing requires explicit conversion (e.g., `int(y)` or `str(x)`) for such mixed-type operations.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It prints 30 as a string
Why it's wrong here
A TypeError is raised before any output, since + cannot combine int and str; no coercion to string happens. It is tempting because converting x with str(x) would produce "1020", but the code performs no such conversion.
- ✗
It prints 1020
Why it's wrong here
Python raises a TypeError instead of concatenating, because + between int and str is undefined; only str + str joins text. It is tempting because 1020 looks like string concatenation, which would occur if x were the string "10" rather than the integer 10.
- ✗
It prints 30
Why it's wrong here
Adding an int and a str raises TypeError, so nothing prints. Concatenation is tempting because both operands look numeric, and 30 would be correct if y were defined as y = 20 without quotes, or if the code used int(y) to convert it first.
- ✓
It raises a TypeError
Why this is correct
Python does not implicitly coerce between int and str, so the + operator has no valid implementation for these mixed operand types. The interpreter raises a TypeError at runtime rather than concatenating or summing, because str.__add__ rejects an int operand and int.__add__ rejects a str.
Go deeper
Related to this question
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 →
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.