PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 16


What is the expected output of the following snippet?

Show Answer
Correct Answer: C

C

Discussion

3 comments
Sign in to comment
EfrenOption: C
Apr 16, 2021

step by step: >>> lst=[1,2,3,4] >>> lst [1, 2, 3, 4] >>> lst=lst[-3:-2] >>> lst [2] >>> lst=lst[-1] >>> lst 2

Ello2023Option: C
May 11, 2023

A list lst is initialized with the values [1,2,3,4]. lst[-3:-2] is a list slice that returns a new list containing the elements from the original list starting at the index -3 (i.e., the third element from the end) and up to but not including the element at index -2 (i.e., the second element from the end). This slice returns the sublist [2]. lst[-1] accesses the last element of the sublist [2]. This returns the value 2. The value 2 is assigned to the variable lst. The final statement print(lst) prints the value of lst, which is 2. So, the output of the code is 2.

macxszOption: C
May 3, 2022

answer is C. 2