100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 190
A developer tests negative list indices. The following code prints 'b'. Which explanation best accounts for that observed behavior?letters=["a","b","c","d"]
print(letters[-3])
- Negative list indices count backward from the end, with -1 selecting the last element.
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
- split converts a string to parts using a delimiter; join combines string parts with a separator.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints 'b'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The list slicing excludes stop topic does not explain why the code prints 'b'. The relevant Python rule is: Negative list indices count backward from the end, with -1 selecting the last element.
C:The string negative indexing and slices topic does not explain why the code prints 'b'. The relevant Python rule is: Negative list indices count backward from the end, with -1 selecting the last element.
D:The split and join strings topic does not explain why the code prints 'b'. The relevant Python rule is: Negative list indices count backward from the end, with -1 selecting the last element.
Question 191
A learner is checking negative list indices. After this modification, what does Python 3 actually do?nums=[4,6,8]
print(nums[-4])
- Raises KeyError
- Raises ValueError
- Raises IndexError
- Raises TypeError
Explanation
Correct Answer
C:The snippet raises indexerror. Negative list indices count backward from the end, with -1 selecting the last element.
Incorrect Answers
A:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises indexerror. Negative list indices count backward from the end, with -1 selecting the last element.
B:This predicts that the snippet raises valueerror, but executing the displayed Python 3 code raises indexerror. Negative list indices count backward from the end, with -1 selecting the last element.
D:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises indexerror. Negative list indices count backward from the end, with -1 selecting the last element.
Question 192
A learner is checking negative list indices. Which final result follows from this separate test?matrix=[[1,2],[3,4]]
print(matrix[-1][-1])
- Prints '5'
- Prints '4'
- Prints '3'
- Prints '6'
Explanation
Correct Answer
B:The snippet prints '4'. Negative list indices count backward from the end, with -1 selecting the last element.
Incorrect Answers
A:This predicts that the snippet prints '5', but executing the displayed Python 3 code prints '4'. Negative list indices count backward from the end, with -1 selecting the last element.
C:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '4'. Negative list indices count backward from the end, with -1 selecting the last element.
D:This predicts that the snippet prints '6', but executing the displayed Python 3 code prints '4'. Negative list indices count backward from the end, with -1 selecting the last element.
Question 193
A learner is checking list slicing excludes stop. What is the exact printed result or uncaught exception?nums=[2,4,6,8,10]
print(nums[1:4])
- Prints '[8, 6, 4]'
- Prints '[4, 6]'
- Prints '[4, 6, 8]'
- Prints '[6, 8]'
Explanation
Correct Answer
C:The snippet prints '[4, 6, 8]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Incorrect Answers
A:This predicts that the snippet prints '[8, 6, 4]', but executing the displayed Python 3 code prints '[4, 6, 8]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
B:This predicts that the snippet prints '[4, 6]', but executing the displayed Python 3 code prints '[4, 6, 8]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
D:This predicts that the snippet prints '[6, 8]', but executing the displayed Python 3 code prints '[4, 6, 8]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Question 194
A developer tests list slicing excludes stop. The following code prints '[0, 1]'. Which explanation best accounts for that observed behavior?a=[0,1,2,3]
print(a[:2])
- list.insert(i, x) inserts x before position i and shifts later elements rather than replacing them.
- The optional third slice component controls stride, including reverse traversal with a negative step.
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints '[0, 1]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The insert location and shifting topic does not explain why the code prints '[0, 1]'. The relevant Python rule is: List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
B:The strided list slices topic does not explain why the code prints '[0, 1]'. The relevant Python rule is: List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
D:The dictionary items and values topic does not explain why the code prints '[0, 1]'. The relevant Python rule is: List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Question 195
A learner is checking list slicing excludes stop. After this modification, what does Python 3 actually do?letters=["x","y","z"]
print(letters[1:])
- Prints "['y', 'z']"
- Prints "['y']"
- Prints "['z', 'y']"
- Prints "['z']"
Explanation
Correct Answer
A:The snippet prints "['y', 'z']". List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Incorrect Answers
B:This predicts that the snippet prints "['y']", but executing the displayed Python 3 code prints "['y', 'z']". List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
C:This predicts that the snippet prints "['z', 'y']", but executing the displayed Python 3 code prints "['y', 'z']". List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
D:This predicts that the snippet prints "['z']", but executing the displayed Python 3 code prints "['y', 'z']". List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Question 196
A learner is checking list slicing excludes stop. Which final result follows from this separate test?data=[1,2,3,4,5]
print(data[-3:-1])
- Prints '[3]'
- Prints '[4]'
- Prints '[4, 3]'
- Prints '[3, 4]'
Explanation
Correct Answer
D:The snippet prints '[3, 4]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Incorrect Answers
A:This predicts that the snippet prints '[3]', but executing the displayed Python 3 code prints '[3, 4]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
B:This predicts that the snippet prints '[4]', but executing the displayed Python 3 code prints '[3, 4]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
C:This predicts that the snippet prints '[4, 3]', but executing the displayed Python 3 code prints '[3, 4]'. List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
Question 197
A learner is checking strided list slices. What is the exact printed result or uncaught exception?a=list(range(7))
print(a[::2])
- Prints '[0, 2, 4]'
- Prints '[2, 4, 6]'
- Prints '[6, 4, 2, 0]'
- Prints '[0, 2, 4, 6]'
Explanation
Correct Answer
D:The snippet prints '[0, 2, 4, 6]'. The optional third slice component controls stride, including reverse traversal with a negative step.
Incorrect Answers
A:This predicts that the snippet prints '[0, 2, 4]', but executing the displayed Python 3 code prints '[0, 2, 4, 6]'. The optional third slice component controls stride, including reverse traversal with a negative step.
B:This predicts that the snippet prints '[2, 4, 6]', but executing the displayed Python 3 code prints '[0, 2, 4, 6]'. The optional third slice component controls stride, including reverse traversal with a negative step.
C:This predicts that the snippet prints '[6, 4, 2, 0]', but executing the displayed Python 3 code prints '[0, 2, 4, 6]'. The optional third slice component controls stride, including reverse traversal with a negative step.
Question 198
A developer tests strided list slices. The following code prints '[5, 4, 3, 2, 1]'. Which explanation best accounts for that observed behavior?a=[1,2,3,4,5]
print(a[::-1])
- Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
- The optional third slice component controls stride, including reverse traversal with a negative step.
- dict.get(key, default) returns the default for a missing key, unlike direct subscription.
- String methods such as find, replace and count return information or new strings without mutating the original.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '[5, 4, 3, 2, 1]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The tuple unpacking arity topic does not explain why the code prints '[5, 4, 3, 2, 1]'. The relevant Python rule is: The optional third slice component controls stride, including reverse traversal with a negative step.
C:The dictionary get with fallback topic does not explain why the code prints '[5, 4, 3, 2, 1]'. The relevant Python rule is: The optional third slice component controls stride, including reverse traversal with a negative step.
D:The find replace and count methods topic does not explain why the code prints '[5, 4, 3, 2, 1]'. The relevant Python rule is: The optional third slice component controls stride, including reverse traversal with a negative step.
Question 199
A learner is checking strided list slices. After this modification, what does Python 3 actually do?a=list("abcdef")
print(a[1::2])
- Prints "['b', 'd', 'f']"
- Prints "['b', 'd']"
- Prints "['d', 'f']"
- Prints "['f', 'd', 'b']"
Explanation
Correct Answer
A:The snippet prints "['b', 'd', 'f']". The optional third slice component controls stride, including reverse traversal with a negative step.
Incorrect Answers
B:This predicts that the snippet prints "['b', 'd']", but executing the displayed Python 3 code prints "['b', 'd', 'f']". The optional third slice component controls stride, including reverse traversal with a negative step.
C:This predicts that the snippet prints "['d', 'f']", but executing the displayed Python 3 code prints "['b', 'd', 'f']". The optional third slice component controls stride, including reverse traversal with a negative step.
D:This predicts that the snippet prints "['f', 'd', 'b']", but executing the displayed Python 3 code prints "['b', 'd', 'f']". The optional third slice component controls stride, including reverse traversal with a negative step.
Question 200
A learner is checking strided list slices. Which final result follows from this separate test?a=[3,6,9,12,15,18]
print(a[-2::-2])
- Prints '[9, 3]'
- Prints '[3, 9, 15]'
- Prints '[15, 9]'
- Prints '[15, 9, 3]'
Explanation
Correct Answer
D:The snippet prints '[15, 9, 3]'. The optional third slice component controls stride, including reverse traversal with a negative step.
Incorrect Answers
A:This predicts that the snippet prints '[9, 3]', but executing the displayed Python 3 code prints '[15, 9, 3]'. The optional third slice component controls stride, including reverse traversal with a negative step.
B:This predicts that the snippet prints '[3, 9, 15]', but executing the displayed Python 3 code prints '[15, 9, 3]'. The optional third slice component controls stride, including reverse traversal with a negative step.
C:This predicts that the snippet prints '[15, 9]', but executing the displayed Python 3 code prints '[15, 9, 3]'. The optional third slice component controls stride, including reverse traversal with a negative step.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests