PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Which function is used to read user input as a string?
⚠ Common exam trap
Python Institute often tests the distinction between `input()` and `raw_input()` (the Python 2 equivalent) or confuses candidates by listing file or dictionary methods like `read()` or `get()` as plausible input functions.
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
✓
input()
The `input()` function is the correct answer because it is the built-in Python function specifically designed to read a line of text from the user via standard input (stdin). It always returns the input as a string, regardless of whether the user types digits or other characters, making it the standard tool for console input 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.
- ✗
read()
Why it's wrong here
Python's read() is a file object method that pulls raw bytes or characters from an open file, not from the keyboard, so it cannot collect interactive user input. It is tempting because its name suggests reading, and it is genuinely correct when consuming data from an opened file handle.
- ✗
scan()
Why it's wrong here
No built-in Python function named scan() exists; input gathering is handled by input(), which returns a string. The name is tempting because other languages, such as C via scanf() and Java via Scanner, use scan-style constructs for reading typed input, so prior experience can mislead candidates.
- ✗
get()
Why it's wrong here
get() is a dictionary method returning the value for a key, not a console input reader. It is tempting because it retrieves data, but that data comes from an existing mapping. Reading user input as a string requires input(), which returns the entered line.
- ✓
input()
Why this is correct
input() reads a line from standard input, strips the trailing newline, and returns it as a string. That matches the stem's requirement to read user input as a string, unlike functions that evaluate the entered text or read from files.
Go deeper
Related to this question
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 →
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.