Courseiva
Computer Programming and Python FundamentalshardMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

Given the code: my_list = [1, 2, 3, 4, 5]. What is the output of print(my_list[-3:-1])?

⚠ Common exam trap

The trap here is that candidates often forget that the end index in a slice is exclusive, causing them to include the element at index -1 and choose option D instead of B.

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

[3, 4]

Python list slicing with negative indices counts from the end of the list. my_list[-3:-1] starts at index -3 (value 3) and goes up to but does not include index -1 (value 5), so it returns [3, 4].

Answer analysis

Option-by-option breakdown

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

  • [4, 5]

    Why it's wrong here

    This would be my_list[-2:].

  • [3, 4]

    Why this is correct

    Negative indices: -3 corresponds to index 2 (value 3), -1 corresponds to index 4 (value 5) but stop exclusive, so indices 2 and 3: [3,4].

  • [2, 3]

    Why it's wrong here

    This would be my_list[-4:-2].

  • [3, 4, 5]

    Why it's wrong here

    This would be my_list[-3:].

About these practice questions

This PCEP question is part of Courseiva's 498-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.