PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 18


How many elements will the list2 list contain after execution of the following snippet?

Show Answer
Correct Answer: C

C

Discussion

5 comments
Sign in to comment
AvidulamOption: C
Feb 26, 2021

Negative step changes a way, slice notation works. It makes the slice be built from the tail of the list. So, it goes from the last element to the first element. So [-1:1:-1] will start from last element of the list and will end end at 2nd element of list, thus as 0th and 1st are sliced we will be left with 7 elements

naveenbv80Option: C
Dec 2, 2022

Answer is C list1 = [False for i in range(1, 10)] print(list1) list2 = list1[-1:1:-1] print(list2) [False, False, False, False, False, False, False, False, False] [False, False, False, False, False, False, False]

shilpadkOption: C
Nov 23, 2023

-1:1:-1 first => start of string (-1 is last index) second => end of string (1 is second index from start) last -1 => step (negative for reverse)

chr000
Aug 18, 2020

what it is means list1[-1:1:-1] ???

kauser
Aug 24, 2020

range[start:stop(excluding):step]

Efren
Apr 16, 2021

YOu maybe understand better with this example: >>> list1=[i for i in range(1,10)] >>> list1 [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list2=list1[-1:1:-1] >>> list2 [9, 8, 7, 6, 5, 4, 3]

macxszOption: C
May 3, 2022

C. seven