100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 230
A developer tests del and list slice deletion. The following code prints '[2, 8]'. Which explanation best accounts for that observed behavior?a=[2,4,6,8]
del a[1:3]
print(a)
- A comprehension evaluates its expression for each source element that passes its optional if filter.
- del removes a list element or slice and shifts surviving elements; it does not produce a return value.
- list.insert(i, x) inserts x before position i and shifts later elements rather than replacing them.
- sorted produces a new sorted list; list.sort changes the original list and returns None.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '[2, 8]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The list comprehension condition topic does not explain why the code prints '[2, 8]'. The relevant Python rule is: del removes a list element or slice and shifts surviving elements; it does not produce a return value.
C:The insert location and shifting topic does not explain why the code prints '[2, 8]'. The relevant Python rule is: del removes a list element or slice and shifts surviving elements; it does not produce a return value.
D:The sorted result versus in-place sort topic does not explain why the code prints '[2, 8]'. The relevant Python rule is: del removes a list element or slice and shifts surviving elements; it does not produce a return value.
Question 231
A learner is checking del and list slice deletion. After this modification, what does Python 3 actually do?a=[1,2,3,4,5]
del a[::2]
print(a)
- Prints '[4]'
- Prints '[4, 2]'
- Prints '[2]'
- Prints '[2, 4]'
Explanation
Correct Answer
D:The snippet prints '[2, 4]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
Incorrect Answers
A:This predicts that the snippet prints '[4]', but executing the displayed Python 3 code prints '[2, 4]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
B:This predicts that the snippet prints '[4, 2]', but executing the displayed Python 3 code prints '[2, 4]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
C:This predicts that the snippet prints '[2]', but executing the displayed Python 3 code prints '[2, 4]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
Question 232
During a review of del and list slice deletion, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
a=[2,4,6,8]
del a[1:3]
print(a)
Program B:
a=[1,2,3,4,5]
del a[::2]
print(a)
Program C:
a=[7,8]
del a[:]
print(a)
- Program A prints '[4, 5]'.
- Program B prints '[2, 4]'.
- Program C prints '[]'.
- Program C prints '-1'.
- Program B prints '[4, 5]'.
Explanation
Correct Answers
B:Running Program B prints '[2, 4]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
C:Running Program C prints '[]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
Incorrect Answers
A:Program A does not produce '[4, 5]'; its verified result is: Prints '[2, 8]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
D:Program C does not produce '-1'; its verified result is: Prints '[]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
E:Program B does not produce '[4, 5]'; its verified result is: Prints '[2, 4]'. del removes a list element or slice and shifts surviving elements; it does not produce a return value.
Question 233
A learner is checking list membership and index. What is the exact printed result or uncaught exception?a=[4,7,4]
print(a.index(4))
- Prints '0'
- Prints '-1'
- Prints '1'
- Prints '2'
Explanation
Correct Answer
A:The snippet prints '0'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Incorrect Answers
B:This predicts that the snippet prints '-1', but executing the displayed Python 3 code prints '0'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
C:This predicts that the snippet prints '1', but executing the displayed Python 3 code prints '0'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
D:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '0'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Question 234
A developer tests list membership and index. The following code prints 'false'. Which explanation best accounts for that observed behavior?a=["a","b"]
print("c" in a)
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- Negative list indices count backward from the end, with -1 selecting the last element.
- Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
- Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'false'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The list slicing excludes stop topic does not explain why the code prints 'false'. The relevant Python rule is: Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
B:The negative list indices topic does not explain why the code prints 'false'. The relevant Python rule is: Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
D:The list alias versus independent copy topic does not explain why the code prints 'false'. The relevant Python rule is: Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Question 235
A learner is checking list membership and index. After this modification, what does Python 3 actually do?a=[2,3,5]
print(a.index(4))
- Raises TypeError
- Raises IndexError
- Raises KeyError
- Raises ValueError
Explanation
Correct Answer
D:The snippet raises valueerror. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Incorrect Answers
A:This predicts that the snippet raises typeerror, but executing the displayed Python 3 code raises valueerror. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
B:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises valueerror. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
C:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises valueerror. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Question 236
During a review of list membership and index, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
a=["a","b"]
print("c" in a)
Program B:
a=[2,3,5]
print(a.index(4))
Program C:
a=[1,2,3]
print(2 not in a)
- Program A prints 'olleh'.
- Program C prints "['b']".
- Program B raises valueerror.
- Program C prints 'false'.
- Program B prints "{'a': 8}".
Explanation
Correct Answers
C:Running Program B raises valueerror. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
D:Running Program C prints 'false'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Incorrect Answers
A:Program A does not produce 'olleh'; its verified result is: Prints 'False'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
B:Program C does not produce "['b']"; its verified result is: Prints 'False'. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
E:Program B does not produce "{'a': 8}"; its verified result is: Raises ValueError. Membership searches list elements by equality; .index returns the first matching position or raises ValueError.
Question 237
A learner is checking single-element tuple comma. What is the exact printed result or uncaught exception?x=(4,)
print(type(x).__name__)
- Prints 'elput'
- Prints 'tuple?'
- Prints 'tupl'
- Prints 'tuple'
Explanation
Correct Answer
D:The snippet prints 'tuple'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Incorrect Answers
A:This predicts that the snippet prints 'elput', but executing the displayed Python 3 code prints 'tuple'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
B:This predicts that the snippet prints 'tuple?', but executing the displayed Python 3 code prints 'tuple'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
C:This predicts that the snippet prints 'tupl', but executing the displayed Python 3 code prints 'tuple'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Question 238
A developer tests single-element tuple comma. The following code prints 'int'. Which explanation best accounts for that observed behavior?x=(4)
print(type(x).__name__)
- The optional third slice component controls stride, including reverse traversal with a negative step.
- items yields key/value pairs while values yields values; unpacking pairs preserves their association.
- A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
- pop removes and returns an indexed element, using the last position when no index is supplied.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'int'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The strided list slices topic does not explain why the code prints 'int'. The relevant Python rule is: A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
B:The dictionary items and values topic does not explain why the code prints 'int'. The relevant Python rule is: A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
D:The pop returns and removes by index topic does not explain why the code prints 'int'. The relevant Python rule is: A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Question 239
A learner is checking single-element tuple comma. After this modification, what does Python 3 actually do?t="ok",
print(t)
- Prints "('ok',)"
- Prints '()'
- Prints 'tuple'
- Prints "('ok', 0)"
Explanation
Correct Answer
A:The snippet prints "('ok',)". A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Incorrect Answers
B:This predicts that the snippet prints '()', but executing the displayed Python 3 code prints "('ok',)". A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
C:This predicts that the snippet prints 'tuple', but executing the displayed Python 3 code prints "('ok',)". A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
D:This predicts that the snippet prints "('ok', 0)", but executing the displayed Python 3 code prints "('ok',)". A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Question 240
During a review of single-element tuple comma, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
x=(4)
print(type(x).__name__)
Program B:
t="ok",
print(t)
Program C:
x=(2+3,)
print(len(x))
- Program B prints 'zbc abc'.
- Program C prints '5'.
- Program B prints "('ok',)".
- Program A prints 'bcd'.
- Program C prints '1'.
Explanation
Correct Answers
C:Running Program B prints "('ok',)". A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
E:Running Program C prints '1'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Incorrect Answers
A:Program B does not produce 'zbc abc'; its verified result is: Prints "('ok',)". A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
B:Program C does not produce '5'; its verified result is: Prints '1'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
D:Program A does not produce 'bcd'; its verified result is: Prints 'int'. A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests