100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 270
A developer tests dictionary items and values. The following code prints '[4, 5]'. Which explanation best accounts for that observed behavior?d={"x":4,"y":5}
print(list(d.values()))
- items yields key/value pairs while values yields values; unpacking pairs preserves their association.
- Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
- String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
- Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints '[4, 5]'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The list alias versus independent copy topic does not explain why the code prints '[4, 5]'. The relevant Python rule is: items yields key/value pairs while values yields values; unpacking pairs preserves their association.
C:The string negative indexing and slices topic does not explain why the code prints '[4, 5]'. The relevant Python rule is: items yields key/value pairs while values yields values; unpacking pairs preserves their association.
D:The mutable objects inside tuple topic does not explain why the code prints '[4, 5]'. The relevant Python rule is: items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Question 271
A learner is checking dictionary items and values. After this modification, what does Python 3 actually do?d={"a":1,"b":2}
print([k for k,v in d.items() if v>1])
- Prints '[]'
- Prints "['b']"
- Prints "['B']"
- Prints "['b', 'x']"
Explanation
Correct Answer
B:The snippet prints "['b']". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Incorrect Answers
A:This predicts that the snippet prints '[]', but executing the displayed Python 3 code prints "['b']". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
C:This predicts that the snippet prints "['b']", but executing the displayed Python 3 code prints "['b']". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
D:This predicts that the snippet prints "['b', 'x']", but executing the displayed Python 3 code prints "['b']". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Question 272
During a review of dictionary items and values, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
d={"x":4,"y":5}
print(list(d.values()))
Program B:
d={"a":1,"b":2}
print([k for k,v in d.items() if v>1])
Program C:
d={"p":2,"q":4}
print(sum(v for _,v in d.items()))
- Program B prints 'olleh'.
- Program B prints "['b']".
- Program C prints '6'.
- Program C prints '5'.
- Program A prints '[4, 5]'.
- Program A raises keyerror.
Explanation
Correct Answers
B:Running Program B prints "['b']". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
C:Running Program C prints '6'. items yields key/value pairs while values yields values; unpacking pairs preserves their association.
E:Running Program A prints '[4, 5]'. items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Incorrect Answers
A:Program B does not produce 'olleh'; its verified result is: Prints "['b']". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
D:Program C does not produce '5'; its verified result is: Prints '6'. items yields key/value pairs while values yields values; unpacking pairs preserves their association.
F:Program A does not raises keyerror; its verified result is: Prints '[4, 5]'. items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Question 273
A learner is checking string negative indexing and slices. What is the exact printed result or uncaught exception?s="python"
print(s[-2:])
- Prints 'no'
- Prints 'o'
- Prints 'on?'
- Prints 'on'
Explanation
Correct Answer
D:The snippet prints 'on'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Incorrect Answers
A:This predicts that the snippet prints 'no', but executing the displayed Python 3 code prints 'on'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
B:This predicts that the snippet prints 'o', but executing the displayed Python 3 code prints 'on'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
C:This predicts that the snippet prints 'on?', but executing the displayed Python 3 code prints 'on'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Question 274
A developer tests string negative indexing and slices. The following code prints 'bcd'. Which explanation best accounts for that observed behavior?s="ABCDE"
print(s[1:4])
- items yields key/value pairs while values yields values; unpacking pairs preserves their association.
- The optional third slice component controls stride, including reverse traversal with a negative step.
- String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
- dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints 'bcd'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The dictionary items and values topic does not explain why the code prints 'bcd'. The relevant Python rule is: String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
B:The strided list slices topic does not explain why the code prints 'bcd'. The relevant Python rule is: String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
D:The dictionary get with fallback topic does not explain why the code prints 'bcd'. The relevant Python rule is: String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Question 275
A learner is checking string negative indexing and slices. After this modification, what does Python 3 actually do?s="Hello"
print(s[::-1])
- Prints 'Hello'
- Prints 'olleH'
- Prints 'olleH?'
- Prints 'olle'
Explanation
Correct Answer
B:The snippet prints 'olleh'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Incorrect Answers
A:This predicts that the snippet prints 'hello', but executing the displayed Python 3 code prints 'olleh'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
C:This predicts that the snippet prints 'olleh?', but executing the displayed Python 3 code prints 'olleh'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
D:This predicts that the snippet prints 'olle', but executing the displayed Python 3 code prints 'olleh'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Question 276
During a review of string negative indexing and slices, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
s="ABCDE"
print(s[1:4])
Program B:
s="Hello"
print(s[::-1])
Program C:
s="banana"
print(s[::2])
- Program C prints '[7]'.
- Program C prints 'bnn'.
- Program A prints 'bnn'.
- Program B prints 'false'.
- Program A prints 'bcd'.
- Program B prints 'olleh'.
Explanation
Correct Answers
B:Running Program C prints 'bnn'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
E:Running Program A prints 'bcd'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
F:Running Program B prints 'olleh'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Incorrect Answers
A:Program C does not produce '[7]'; its verified result is: Prints 'bnn'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
C:Program A does not produce 'bnn'; its verified result is: Prints 'BCD'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
D:Program B does not produce 'false'; its verified result is: Prints 'olleH'. String indexing and slicing resemble list indexing, but slicing returns a new string and excludes the stop.
Question 277
A learner is checking string immutability and reassembly. What is the exact printed result or uncaught exception?s="cat"
s[0]="b"
- Raises IndexError
- Raises ValueError
- Raises TypeError
- Raises KeyError
Explanation
Correct Answer
C:The snippet raises typeerror. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
Incorrect Answers
A:This predicts that the snippet raises indexerror, but executing the displayed Python 3 code raises typeerror. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
B:This predicts that the snippet raises valueerror, but executing the displayed Python 3 code raises typeerror. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
D:This predicts that the snippet raises keyerror, but executing the displayed Python 3 code raises typeerror. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
Question 278
A developer tests string immutability and reassembly. The following code prints 'bat'. Which explanation best accounts for that observed behavior?s="cat"
s="b"+s[1:]
print(s)
- Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
- Tuple immutability protects its slots, but a mutable object stored inside a tuple can change in place.
- When a dictionary literal repeats the same key, the later value replaces the earlier value.
- dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Explanation
Correct Answer
A:This is the operative language rule for the code. It directly explains why the example prints 'bat'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
B:The mutable objects inside tuple topic does not explain why the code prints 'bat'. The relevant Python rule is: Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
C:The duplicate dictionary keys overwritten topic does not explain why the code prints 'bat'. The relevant Python rule is: Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
D:The dictionary get with fallback topic does not explain why the code prints 'bat'. The relevant Python rule is: Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
Question 279
A learner is checking string immutability and reassembly. After this modification, what does Python 3 actually do?word="go"
word+= "!"
print(word)
- Prints 'go!'
- Prints 'go!?'
- Prints '!og'
- Prints 'go'
Explanation
Correct Answer
A:The snippet prints 'go!'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
Incorrect Answers
B:This predicts that the snippet prints 'go!?', but executing the displayed Python 3 code prints 'go!'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
C:This predicts that the snippet prints '!og', but executing the displayed Python 3 code prints 'go!'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
D:This predicts that the snippet prints 'go', but executing the displayed Python 3 code prints 'go!'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
Question 280
During a review of string immutability and reassembly, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
s="cat"
s="b"+s[1:]
print(s)
Program B:
word="go"
word+= "!"
print(word)
Program C:
s="abc"
print(s.replace("a","z"),s)
- Program C prints 'zbc abc'.
- Program B prints 'go!'.
- Program A prints 'bcd'.
- Program A prints 'bat'.
- Program B prints 'bcd'.
- Program C raises nameerror.
Explanation
Correct Answers
A:Running Program C prints 'zbc abc'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
B:Running Program B prints 'go!'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
D:Running Program A prints 'bat'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
Incorrect Answers
C:Program A does not produce 'bcd'; its verified result is: Prints 'bat'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
E:Program B does not produce 'bcd'; its verified result is: Prints 'go!'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
F:Program C does not raises nameerror; its verified result is: Prints 'zbc abc'. Strings are immutable; constructing a new string works but assigning directly into an index raises TypeError.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests