PCAP-31-03 practice question 3 of 25
How many elements will the list2 list contain after execution of the following snippet? list1 = [False for i in range (1, 10) ] list2 = list1 [-1:1:-1]
Full set: 147 questionslist1 comprehension builds nine False values (range(1,10) → 1-9). Slice list1[-1:1:-1] starts at index 8, moves backward by -1, stops before index 1. Indices included: 8,7,6,5,4,3,2 → 7 elements.
A. Slice is non-empty; seven elements selected.
B. Contains seven, not five, elements.
D. Contains seven, not three, elements.
1. Python 3 Library Reference, “Built-in Types — Common sequence operations”, ¶5 (docs.python.org/3/library/stdtypes.html#typesseq-common) – explains negative-step slicing rules.
2. Python 3 Library Reference, “range() objects”, ¶2 (docs.python.org/3/library/stdtypes.html#typesseq-range) – details of range(1,10) endpoints.
Keep practicing
Take the free PCAP-31-03 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCAP-31-03 practice questions
- Question 6Select the valid fun () invocations: (select two answers) def fun (a, b=0): return a*b
- Question 7Is it possible to safely check if a class object has a certain attribute0
- Question 10Which of the equations are True? (Select two answers)
- Question 13Which of the following lambda function definitions are correct? (Select two answers)
- Question 15Which of the following invocations are valid? (Select two answers)
- Question 16Which of the following words can be used as a variable name? (Select two valid names)
