Courseiva
Strings →easyMultiple Choice

Extracting Substrings Using String Slicing in Python

What is the result of the expression 'Hello'[1:3]?

⚠ Common exam trap

Python Institute often tests the off-by-one error in slice stop indices, where candidates mistakenly think the stop index is inclusive and select 'ell' (option D) instead of the correct 'el'.

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

✓

'el'

In Python, string slicing uses the syntax `string[start:stop]`, where `start` is inclusive and `stop` is exclusive. For `'Hello'[1:3]`, the indices are: index 1 = 'e', index 2 = 'l', and index 3 is not included, so the slice returns 'el'. This is a fundamental string slicing behavior defined in Python's sequence protocol.

Answer analysis

Option-by-option breakdown

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

  • ✓

    'el'

    Why this is correct

    Python slicing uses a half-open interval: the start index is included, but the stop index is excluded. In 'hello', the indices are h=0, e=1, l=2, l=3, o=4, so slice [1:3] selects index 1 ('e') and index 2 ('l'), producing 'el'. The character at index 3 is not part of the result because the stop boundary is exclusive.

  • ✗

    'lo'

    Why it's wrong here

    The substring 'lo' occupies indices 2 and 3 in 'hello', so it would be returned by the slice [2:4] (or [2:] for the tail), not by [1:3]. A start of 1 means the slice begins with 'e', and a stop of 3 prevents the character at index 3, 'o', from being included. Therefore 'lo' cannot be the output of this particular slice.

  • ✗

    'He'

    Why it's wrong here

    'He' corresponds to indices 0 and 1, and would require the slice [0:2] to capture the leading 'H' and the following 'e'. The slice [1:3] explicitly starts at index 1, so the initial 'H' is skipped from the start. Thus 'He' is not a possible result of this expression.

  • ✗

    'ell'

    Why it's wrong here

    'ell' consists of indices 1, 2, and 3, which would need the stopping index to be 4 because the stop position is non-inclusive. The slice [1:3] includes only indices 1 and 2, so the second 'l' at index 3 is omitted. Consequently, 'ell' is three characters long, while [1:3] can return at most two characters.

About these practice questions

Courseiva writes every PCAP question from scratch — 421 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 PCAP 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 PCAP exam.