Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 16 discussion

Actual exam question from Python Institute's PCAP
Question #: 16
Topic #: 1
[All PCAP Questions]

What is the expected output of the following snippet?

  • A. 1
  • B. 4
  • C. 2
  • D. 3
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Efren
Highly Voted 3 years, 7 months ago
step by step: >>> lst=[1,2,3,4] >>> lst [1, 2, 3, 4] >>> lst=lst[-3:-2] >>> lst [2] >>> lst=lst[-1] >>> lst 2
upvoted 7 times
...
Ello2023
Highly Voted 1 year, 6 months ago
Selected Answer: C
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.
upvoted 5 times
...
macxsz
Most Recent 2 years, 7 months ago
Selected Answer: C
answer is C. 2
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...