Courseiva

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

Given 's = "Hello"; t = s[0:3]; print(t)', what is the output?

⚠ Common exam trap

Many candidates confuse the exclusive stop index with an inclusive one, leading them to select "Hell" (option C) because they mistakenly include index 3, or they misremember the starting index and pick "ello" (option A).

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

✓

Hel

String slicing in Python uses the syntax `s[start:stop]`, where the stop index is exclusive. For `s = "Hello"`, `s[0:3]` extracts characters from index 0 up to but not including index 3, resulting in indices 0 ('H'), 1 ('e'), and 2 ('l'), giving the substring "Hel".

Answer analysis

Option-by-option breakdown

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

  • ✗

    ello

    Why it's wrong here

    That would be s[1:5].

  • ✗

    H

    Why it's wrong here

    The slice s[0:3] returns three characters, not one. The temptation is to read '0:3' as a single index, but the colon denotes a range from index 0 up to (not including) index 3, yielding 'Hel'.

  • ✗

    Hell

    Why it's wrong here

    Slicing s[0:3] returns characters at indices 0, 1 and 2, which is 'Hel', not 'Hell'. The temptation is to count the stop index inclusively, but Python's slice stop is exclusive, so index 3 ('l') is excluded.

  • ✓

    Hel

    Why this is correct

    Slicing extracts characters from index 0 up to, but excluding, index 3, yielding "Hel". The start index defaults to 0, and the stop index is exclusive, so the character at position 3 ("l") is omitted. This satisfies the stem's requirement to print the first three characters of "Hello".

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 →

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.