Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A beginner writes: x = '10'; y = 20; print(x + y). What happens?

⚠ Common exam trap

The trap here is that candidates often expect Python to behave like JavaScript or PHP, which implicitly coerce types, but Python strictly requires explicit type conversion for mixed-type operations.

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

✓

Raises TypeError

Python's type system does not allow implicit concatenation of a string and an integer. The variable `x` is a string (`'10'`), and `y` is an integer (`20`). The `+` operator with these types triggers a `TypeError: unsupported operand type(s) for +: 'int' and 'str'` (or vice versa), as Python refuses to guess the programmer's intent.

Answer analysis

Option-by-option breakdown

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

  • ✓

    Raises TypeError

    Why this is correct

    Python does not implicitly convert between str and int, so adding the string '10' to the integer 20 raises TypeError. This satisfies the question by identifying the runtime error produced when concatenation and addition are mixed across incompatible types.

  • ✗

    Prints 30

    Why it's wrong here

    Adding a str to an int raises TypeError, so nothing prints; Python never coerces '10' to 10 implicitly. It is tempting because arithmetic on numeric-looking strings feels natural, and int(x) + y would indeed print 30 after explicit conversion.

  • ✗

    Prints 10 + 20

    Why it's wrong here

    Not a string representation.

  • ✗

    Prints 1020

    Why it's wrong here

    TypeError is raised because '+' between str and int is undefined; concatenation requires both operands to be strings. It is tempting because '10' + '20' genuinely yields '1020', and str(y) would make that output correct here.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.