100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
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.
Question 241
A learner is checking tuple immutability. What is the exact printed result or uncaught exception?t=(1,2)
t[0]=9
- Raises KeyError
- Raises TypeError
- Raises IndexError
- Raises ValueError
Explanation
Correct Answer
B:The snippet raises typeerror. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Incorrect Answers
A:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises typeerror. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
C:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises typeerror. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
D:This predicts that the snippet raises valueerror, but executing the displayed Python 3 code raises typeerror. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Question 242
A developer tests tuple immutability. The following code prints '(1, 2, 3)'. Which explanation best accounts for that observed behavior?t=(1,2)
t=t+(3,)
print(t)
- A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
- A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
- split converts a string to parts using a delimiter; join combines string parts with a separator.
- del removes a list element or slice and shifts surviving elements; it does not produce a return value.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints '(1, 2, 3)'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The single-element tuple comma topic does not explain why the code prints '(1, 2, 3)'. The relevant Python rule is: A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
C:The split and join strings topic does not explain why the code prints '(1, 2, 3)'. The relevant Python rule is: A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
D:The del and list slice deletion topic does not explain why the code prints '(1, 2, 3)'. The relevant Python rule is: A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Question 243
A learner is checking tuple immutability. After this modification, what does Python 3 actually do?t=("a","b")
print(t[-1])
- Prints 'B'
- Prints 'b?'
- Prints 'b'
- Prints ''
Explanation
Correct Answer
C:The snippet prints 'b'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Incorrect Answers
A:This predicts that the snippet prints 'b', but executing the displayed Python 3 code prints 'b'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
B:This predicts that the snippet prints 'b?', but executing the displayed Python 3 code prints 'b'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
D:This predicts that the snippet prints '', but executing the displayed Python 3 code prints 'b'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Question 244
During a review of tuple immutability, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
t=(1,2)
t=t+(3,)
print(t)
Program B:
t=("a","b")
print(t[-1])
Program C:
t=(5,6)
print(t[0:1])
- Program C prints 'true'.
- Program C prints '(5,)'.
- Program B prints '4'.
- Program A raises syntaxerror.
- Program B prints 'b'.
Explanation
Correct Answers
B:Running Program C prints '(5,)'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
E:Running Program B prints 'b'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Incorrect Answers
A:Program C does not produce 'true'; its verified result is: Prints '(5,)'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
C:Program B does not produce '4'; its verified result is: Prints 'b'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
D:Program A does not raises syntaxerror; its verified result is: Prints '(1, 2, 3)'. A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Question 245
A learner is checking mutable objects inside tuple. What is the exact printed result or uncaught exception?t=([1],2)
t[0].append(3)
print(t)
- Prints '([1, 3],)'
- Prints '([1, 3], 2)'
- Prints '([1, 3], 2, 0)'
- Prints '(2, [1, 3])'
Explanation
Correct Answer
B:The snippet prints '([1, 3], 2)'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Incorrect Answers
A:This predicts that the snippet prints '([1, 3],)', but executing the displayed Python 3 code prints '([1, 3], 2)'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
C:This predicts that the snippet prints '([1, 3], 2, 0)', but executing the displayed Python 3 code prints '([1, 3], 2)'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
D:This predicts that the snippet prints '(2, [1, 3])', but executing the displayed Python 3 code prints '([1, 3], 2)'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Question 246
A developer tests mutable objects inside tuple. The following code prints '([4, 9],)'. Which explanation best accounts for that observed behavior?t=([4,5],)
t[0][1]=9
print(t)
- Negative list indices count backward from the end, with -1 selecting the last element.
- Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
- Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
- Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints '([4, 9],)'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The negative list indices topic does not explain why the code prints '([4, 9],)'. The relevant Python rule is: Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
C:The list alias versus independent copy topic does not explain why the code prints '([4, 9],)'. The relevant Python rule is: Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
D:The tuple unpacking arity topic does not explain why the code prints '([4, 9],)'. The relevant Python rule is: Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Question 247
A learner is checking mutable objects inside tuple. After this modification, what does Python 3 actually do?t=([1],)
t[0]=[2]
- Raises KeyError
- Raises IndexError
- Raises ValueError
- Raises TypeError
Explanation
Correct Answer
D:The snippet raises typeerror. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Incorrect Answers
A:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises typeerror. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
B:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises typeerror. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
C:This predicts that the snippet raises valueerror, but executing the displayed Python 3 code raises typeerror. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Question 248
During a review of mutable objects inside tuple, three independent Python 3 fragments are shown. Which TWO statements accurately describe their behavior? (Choose TWO.)Program A:
t=([4,5],)
t[0][1]=9
print(t)
Program B:
t=([1],)
t[0]=[2]
Program C:
t=([],0)
t[0].extend([7,8])
print(t[0])
- Program B raises typeerror.
- Program A prints '[1, 2, 9]'.
- Program B prints "('ok',)".
- Program C prints '[7, 8]'.
- Program C raises keyerror.
Explanation
Correct Answers
A:Running Program B raises typeerror. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
D:Running Program C prints '[7, 8]'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Incorrect Answers
B:Program A does not produce '[1, 2, 9]'; its verified result is: Prints '([4, 9],)'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
C:Program B does not produce "('ok',)"; its verified result is: Raises TypeError. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
E:Program C does not raises keyerror; its verified result is: Prints '[7, 8]'. Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Question 249
A learner is checking tuple unpacking arity. What is the exact printed result or uncaught exception?a,b=(3,4)
print(b-a)
- Prints '1'
- Prints '2'
- Prints '0'
- Prints '3'
Explanation
Correct Answer
A:The snippet prints '1'. Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
Incorrect Answers
B:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '1'. Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
C:This predicts that the snippet prints '0', but executing the displayed Python 3 code prints '1'. Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
D:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '1'. Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
Question 250
A developer tests tuple unpacking arity. The following code prints 'red'. Which explanation best accounts for that observed behavior?x,y=("red","blue")
print(x)
- Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
- The optional third slice component controls stride, including reverse traversal with a negative step.
- Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
- A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'red'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The list alias versus independent copy topic does not explain why the code prints 'red'. The relevant Python rule is: Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
B:The strided list slices topic does not explain why the code prints 'red'. The relevant Python rule is: Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
D:The single-element tuple comma topic does not explain why the code prints 'red'. The relevant Python rule is: Sequence unpacking assigns elements positionally and requires matching targets unless an explicit star target is used.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests