Courseiva
Computer Programming and Python FundamentalsmediumMultiple ChoiceObjective-mapped

PCEP Method chaining Practice Question

What does the following code print? text = 'Hello World'; print(text.replace('o', '0').upper())

⚠ Common exam trap

This question tests chaining string methods. A common mistake is to confuse the order of operations or to forget that replace is case-sensitive (only replaces lowercase 'o').

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

HELL0 W0RLD

The string 'Hello World' is first operated on by replace('o', '0') which replaces all occurrences of 'o' with '0', resulting in 'Hell0 W0rld'. Then .upper() converts all characters to uppercase, yielding 'HELL0 W0RLD'. Therefore, option C is correct. Option A is 'hell0 w0rld' which would require .lower() after replace. Option B is 'HELLO WORLD' which does not apply the replacement. Option D is 'Hell0 W0rld' which is only the result after replace but without .upper().

Answer analysis

Option-by-option breakdown

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

  • hell0 w0rld

    Why it's wrong here

    Incorrect because it shows lowercase result, but .upper() was called.

  • HELLO WORLD

    Why it's wrong here

    Incorrect because it does not show the replacement of 'o' with '0'.

  • HELL0 W0RLD

    Why this is correct

    Correct as described.

  • Hell0 W0rld

    Why it's wrong here

    Incorrect because it shows the result after replace but before .upper().

About these practice questions

Courseiva writes every PCEP question from scratch — 498 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

Same concept, more angles

1 more way this is tested on PCEP

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. What is the output of the following code? print('Hello'.upper())

easy
  • A.hello
  • B.HELLO!
  • C.HELLO
  • D.Hello

Why C: The `.upper()` string method in Python returns a new string with all lowercase letters converted to uppercase. The string `'Hello'` contains the characters 'H', 'e', 'l', 'l', 'o'; after applying `.upper()`, it becomes `'HELLO'`. The output is exactly `HELLO` without any additional characters.

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.