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

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

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 (?) , you can switch to a simple comment.
Switch to a voting comment New
Avidulam
Highly Voted 3 years, 1 month 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 4 months, 4 weeks 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, 4 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
1 year, 11 months ago
Selected Answer: C
C. seven
upvoted 1 times
...
chr000
3 years, 8 months ago
what it is means list1[-1:1:-1] ???
upvoted 1 times
kauser
3 years, 7 months ago
range[start:stop(excluding):step]
upvoted 15 times
...
Efren
3 years 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 20 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 ...