Courseiva

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

A user enters '42' at an input prompt. After executing x = input(), what is the type of x?

⚠ Common exam trap

Watch out — candidates often assume `input()` automatically converts numeric-looking input to an integer or float, because many other languages (like C++ with `cin`) do so, but Python's `input()` always returns a string.

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

The `input()` function in Python always returns the user's input as a string, regardless of whether the input looks like a number. When the user enters '42', it is captured as the string '42', so the type of `x` is `str`. This is because `input()` does not perform any implicit type conversion.

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

    input() returns a string regardless of the characters typed, so entering 42 yields str, not float. float is tempting because numeric-looking input is often converted with float() for decimal handling, which would be correct only if the code explicitly cast the value.

  • ✓

    str

    Why this is correct

    input() always returns a string regardless of what the user types, so entering 42 yields the characters '4' and '2' as a str. No implicit numeric conversion occurs; int() or float() must be called explicitly to obtain a number.

  • ✗

    bool

    Why it's wrong here

    input() always returns a string, so 42 produces str, never bool. bool is tempting because truthiness checks are common in Python, but a bool results only from explicit conversion or a comparison expression, not from reading raw input.

  • ✗

    int

    Why it's wrong here

    input() returns a string, so 42 yields str, not int. int is tempting because the entered characters look numeric and int() conversion is frequently applied afterwards, but that cast must be written explicitly; the raw return type remains str.

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 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.