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 18 discussion

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

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

  • A. zero
  • B. five
  • C. seven
  • D. three
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
Avidulam
Highly Voted 3 years, 9 months ago
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
upvoted 8 times
...
shilpadk
Most Recent 1 year ago
-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)
upvoted 2 times
...
naveenbv80
1 year, 12 months ago
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]
upvoted 2 times
...
macxsz
2 years, 7 months ago
Selected Answer: C
C. seven
upvoted 1 times
...
chr000
4 years, 3 months ago
what it is means list1[-1:1:-1] ???
upvoted 1 times
kauser
4 years, 3 months ago
range[start:stop(excluding):step]
upvoted 15 times
...
Efren
3 years, 7 months ago
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]
upvoted 21 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 ...