100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 210
A developer tests pop returns and removes by index. The following code prints '2 [4, 6]'. Which explanation best accounts for that observed behavior?a=[2,4,6]
x=a.pop(0)
print(x,a)
- pop removes and returns an indexed element, using the last position when no index is supplied.
- String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- Accessing a nested list uses successive indexes: first select the row, then its element.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints '2 [4, 6]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The string negative indexing and slices topic does not explain why the code prints '2 [4, 6]'. The relevant Python rule is: pop removes and returns an indexed element, using the last position when no index is supplied.
C:The list slicing excludes stop topic does not explain why the code prints '2 [4, 6]'. The relevant Python rule is: pop removes and returns an indexed element, using the last position when no index is supplied.
D:The nested list matrix indexing topic does not explain why the code prints '2 [4, 6]'. The relevant Python rule is: pop removes and returns an indexed element, using the last position when no index is supplied.
Question 211
A learner is checking pop returns and removes by index. After this modification, what does Python 3 actually do?a=[3]
print(a.pop(),len(a))
- Prints '0 3'
- Prints '3 0'
- Prints '3 '
- Prints '3 0?'
Explanation
Correct Answer
B:The snippet prints '3 0'. pop removes and returns an indexed element, using the last position when no index is supplied.
Incorrect Answers
A:This predicts that the snippet prints '0 3', but executing the displayed Python 3 code prints '3 0'. pop removes and returns an indexed element, using the last position when no index is supplied.
C:This predicts that the snippet prints '3 ', but executing the displayed Python 3 code prints '3 0'. pop removes and returns an indexed element, using the last position when no index is supplied.
D:This predicts that the snippet prints '3 0?', but executing the displayed Python 3 code prints '3 0'. pop removes and returns an indexed element, using the last position when no index is supplied.
Question 212
During a review of pop returns and removes by index, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
a=[2,4,6]
x=a.pop(0)
print(x,a)
Program B:
a=[3]
print(a.pop(),len(a))
Program C:
a=[]
print(a.pop())
- Program A raises valueerror.
- Program B prints '3 0'.
- Program C prints '9 [7, 8]'.
- Program B prints '[7]'.
- Program C raises indexerror.
Explanation
Correct Answers
B:Running Program B prints '3 0'. pop removes and returns an indexed element, using the last position when no index is supplied.
E:Running Program C raises indexerror. pop removes and returns an indexed element, using the last position when no index is supplied.
Incorrect Answers
A:Program A does not raises valueerror; its verified result is: Prints '2 [4, 6]'. pop removes and returns an indexed element, using the last position when no index is supplied.
C:Program C does not produce '9 [7, 8]'; its verified result is: Raises IndexError. pop removes and returns an indexed element, using the last position when no index is supplied.
D:Program B does not produce '[7]'; its verified result is: Prints '3 0'. pop removes and returns an indexed element, using the last position when no index is supplied.
Question 213
A learner is checking list alias versus independent copy. What is the exact printed result or uncaught exception?a=[1,2]
b=a
b.append(3)
print(a)
- Prints '[1, 2, 3]'
- Prints '[2, 3]'
- Prints '[3, 2, 1]'
- Prints '[1, 2]'
Explanation
Correct Answer
A:The snippet prints '[1, 2, 3]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Incorrect Answers
B:This predicts that the snippet prints '[2, 3]', but executing the displayed Python 3 code prints '[1, 2, 3]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
C:This predicts that the snippet prints '[3, 2, 1]', but executing the displayed Python 3 code prints '[1, 2, 3]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
D:This predicts that the snippet prints '[1, 2]', but executing the displayed Python 3 code prints '[1, 2, 3]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Question 214
A developer tests list alias versus independent copy. The following code prints '[1, 2]'. Which explanation best accounts for that observed behavior?a=[1,2]
b=a[:]
b.append(3)
print(a)
- String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
- Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
- Negative list indices count backward from the end, with -1 selecting the last element.
- 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 '[1, 2]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The string negative indexing and slices topic does not explain why the code prints '[1, 2]'. The relevant Python rule is: Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
C:The negative list indices topic does not explain why the code prints '[1, 2]'. The relevant Python rule is: Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
D:The find replace and count methods topic does not explain why the code prints '[1, 2]'. The relevant Python rule is: Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Question 215
A learner is checking list alias versus independent copy. After this modification, what does Python 3 actually do?a=[1,2]
b=list(a)
b[0]=9
print(a,b)
- Prints '[1, 2] [9, 2'
- Prints ']2 ,9[ ]2 ,1['
- Prints '[1, 2] [9, 2]'
- Prints '[1, 2] [9, 2]?'
Explanation
Correct Answer
C:The snippet prints '[1, 2] [9, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Incorrect Answers
A:This predicts that the snippet prints '[1, 2] [9, 2', but executing the displayed Python 3 code prints '[1, 2] [9, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
B:This predicts that the snippet prints ']2 ,9[ ]2 ,1[', but executing the displayed Python 3 code prints '[1, 2] [9, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
D:This predicts that the snippet prints '[1, 2] [9, 2]?', but executing the displayed Python 3 code prints '[1, 2] [9, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Question 216
During a review of list alias versus independent copy, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
a=[1,2]
b=a[:]
b.append(3)
print(a)
Program B:
a=[1,2]
b=list(a)
b[0]=9
print(a,b)
Program C:
a=[4]
b=a
a[0]+=3
print(b)
- Program A prints '[2, 4]'.
- Program C prints 'bat'.
- Program B prints '[1, 2] [9, 2]'.
- Program B prints '[0, 2, 4, 6]'.
- Program C prints '[7]'.
Explanation
Correct Answers
C:Running Program B prints '[1, 2] [9, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
E:Running Program C prints '[7]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Incorrect Answers
A:Program A does not produce '[2, 4]'; its verified result is: Prints '[1, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
B:Program C does not produce 'bat'; its verified result is: Prints '[7]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
D:Program B does not produce '[0, 2, 4, 6]'; its verified result is: Prints '[1, 2] [9, 2]'. Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Question 217
A learner is checking sorted result versus in-place sort. What is the exact printed result or uncaught exception?a=[3,1,2]
b=sorted(a)
print(a,b)
- Prints '[3, 1, 2] [1, 2, 3'
- Prints '[3, 1, 2] [1, 2, 3]?'
- Prints '[3, 1, 2] [1, 2, 3]'
- Prints ']3 ,2 ,1[ ]2 ,1 ,3['
Explanation
Correct Answer
C:The snippet prints '[3, 1, 2] [1, 2, 3]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
Incorrect Answers
A:This predicts that the snippet prints '[3, 1, 2] [1, 2, 3', but executing the displayed Python 3 code prints '[3, 1, 2] [1, 2, 3]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
B:This predicts that the snippet prints '[3, 1, 2] [1, 2, 3]?', but executing the displayed Python 3 code prints '[3, 1, 2] [1, 2, 3]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
D:This predicts that the snippet prints ']3 ,2 ,1[ ]2 ,1 ,3[', but executing the displayed Python 3 code prints '[3, 1, 2] [1, 2, 3]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
Question 218
A developer tests sorted result versus in-place sort. The following code prints 'none [1, 2, 3]'. Which explanation best accounts for that observed behavior?a=[3,1,2]
r=a.sort()
print(r,a)
- When a dictionary literal repeats the same key, the later value replaces the earlier value.
- pop removes and returns an indexed element, using the last position when no index is supplied.
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- sorted produces a new sorted list; list.sort changes the original list and returns None.
Explanation
Correct Answer
D:This is the operative language rule for the code. It directly explains why the example prints 'none [1, 2, 3]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The duplicate dictionary keys overwritten topic does not explain why the code prints 'none [1, 2, 3]'. The relevant Python rule is: sorted produces a new sorted list; list.sort changes the original list and returns None.
B:The pop returns and removes by index topic does not explain why the code prints 'none [1, 2, 3]'. The relevant Python rule is: sorted produces a new sorted list; list.sort changes the original list and returns None.
C:The list slicing excludes stop topic does not explain why the code prints 'none [1, 2, 3]'. The relevant Python rule is: sorted produces a new sorted list; list.sort changes the original list and returns None.
Question 219
A learner is checking sorted result versus in-place sort. After this modification, what does Python 3 actually do?a=["bb","a","ccc"]
print(sorted(a,key=len))
- Prints "['a', 'bb', 'ccc']"
- Prints "['bb', 'ccc']"
- Prints "['ccc', 'bb', 'a']"
- Prints "['a', 'bb']"
Explanation
Correct Answer
A:The snippet prints "['a', 'bb', 'ccc']". sorted produces a new sorted list; list.sort changes the original list and returns None.
Incorrect Answers
B:This predicts that the snippet prints "['bb', 'ccc']", but executing the displayed Python 3 code prints "['a', 'bb', 'ccc']". sorted produces a new sorted list; list.sort changes the original list and returns None.
C:This predicts that the snippet prints "['ccc', 'bb', 'a']", but executing the displayed Python 3 code prints "['a', 'bb', 'ccc']". sorted produces a new sorted list; list.sort changes the original list and returns None.
D:This predicts that the snippet prints "['a', 'bb']", but executing the displayed Python 3 code prints "['a', 'bb', 'ccc']". sorted produces a new sorted list; list.sort changes the original list and returns None.
Question 220
During a review of sorted result versus in-place sort, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
a=[3,1,2]
r=a.sort()
print(r,a)
Program B:
a=["bb","a","ccc"]
print(sorted(a,key=len))
Program C:
a=[5,2,7]
a.sort(reverse=True)
print(a)
- Program C prints '[1, 4, 2]'.
- Program B prints "['a', 'bb', 'ccc']".
- Program B prints '[3, 1, 2] [1, 2, 3]'.
- Program A prints "['b', 'd', 'f']".
- Program C prints '[7, 5, 2]'.
Explanation
Correct Answers
B:Running Program B prints "['a', 'bb', 'ccc']". sorted produces a new sorted list; list.sort changes the original list and returns None.
E:Running Program C prints '[7, 5, 2]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
Incorrect Answers
A:Program C does not produce '[1, 4, 2]'; its verified result is: Prints '[7, 5, 2]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
C:Program B does not produce '[3, 1, 2] [1, 2, 3]'; its verified result is: Prints "['a', 'bb', 'ccc']". sorted produces a new sorted list; list.sort changes the original list and returns None.
D:Program A does not produce "['b', 'd', 'f']"; its verified result is: Prints 'None [1, 2, 3]'. sorted produces a new sorted list; list.sort changes the original list and returns None.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests