100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 260
During a review of duplicate dictionary keys overwritten, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
d={1:"a",2:"b",1:"z"}
print(len(d))
Program B:
d={"a":2}
d["a"]=8
print(d)
Program C:
d={"k":3}
d["m"]=4
print(len(d))
- Program B prints "{'a': 8}".
- Program C prints '6'.
- Program A prints '2'.
- Program B prints '2 [4, 6]'.
- Program C prints '2'.
- Program A prints '5'.
Explanation
Correct Answers
A:Running Program B prints "{'a': 8}". When a dictionary literal repeats the same key, the later value replaces the earlier value.
C:Running Program A prints '2'. When a dictionary literal repeats the same key, the later value replaces the earlier value.
E:Running Program C prints '2'. When a dictionary literal repeats the same key, the later value replaces the earlier value.
Incorrect Answers
B:Program C does not produce '6'; its verified result is: Prints '2'. When a dictionary literal repeats the same key, the later value replaces the earlier value.
D:Program B does not produce '2 [4, 6]'; its verified result is: Prints "{'a': 8}". When a dictionary literal repeats the same key, the later value replaces the earlier value.
F:Program A does not produce '5'; its verified result is: Prints '2'. When a dictionary literal repeats the same key, the later value replaces the earlier value.
Question 261
A learner is checking dictionary get with fallback. What is the exact printed result or uncaught exception?d={"a":7}
print(d.get("b",0))
- Prints '0'
- Prints '1'
- Prints '2'
- Prints '-1'
Explanation
Correct Answer
A:The snippet prints '0'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Incorrect Answers
B:This predicts that the snippet prints '1', but executing the displayed Python 3 code prints '0'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
C:This predicts that the snippet prints '2', but executing the displayed Python 3 code prints '0'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
D:This predicts that the snippet prints '-1', but executing the displayed Python 3 code prints '0'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Question 262
A developer tests dictionary get with fallback. The following code prints '7'. Which explanation best accounts for that observed behavior?d={"a":7}
print(d.get("a",0))
- A tuple with one item needs a trailing comma; parentheses alone simply group an expression.
- sorted produces a new sorted list; list.sort changes the original list and returns None.
- dict.get(key, default) returns the default for a missing key, unlike direct subscription.
- 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 '7'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The single-element tuple comma topic does not explain why the code prints '7'. The relevant Python rule is: dict.get(key, default) returns the default for a missing key, unlike direct subscription.
B:The sorted result versus in-place sort topic does not explain why the code prints '7'. The relevant Python rule is: dict.get(key, default) returns the default for a missing key, unlike direct subscription.
D:The list alias versus independent copy topic does not explain why the code prints '7'. The relevant Python rule is: dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Question 263
A learner is checking dictionary get with fallback. After this modification, what does Python 3 actually do?d={"x":None}
print(d.get("x",5))
- Prints 'True'
- Prints '0'
- Prints 'None'
- Prints '7'
Explanation
Correct Answer
C:The snippet prints 'none'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Incorrect Answers
A:This predicts that the snippetprints 'true', but executing the displayed Python 3 code prints 'none'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
B:This predicts that the snippet prints '0', but executing the displayed Python 3 code prints 'none'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
D:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints 'none'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Question 264
During a review of dictionary get with fallback, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
d={"a":7}
print(d.get("a",0))
Program B:
d={"x":None}
print(d.get("x",5))
Program C:
d={}
print(d.get("miss"))
- Program C prints '(5,)'.
- Program B prints 'none'.
- Program A prints '0'.
- Program A prints '7'.
- Program C prints 'none'.
- Program B prints 'true'.
Explanation
Correct Answers
B:Running Program B prints 'none'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
D:Running Program A prints '7'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
E:Running Program C prints 'none'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Incorrect Answers
A:Program C does not produce '(5,)'; its verified result is: Prints 'None'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
C:Program A does not produce '0'; its verified result is: Prints '7'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
F:Program B does not produce 'true'; its verified result is: Prints 'None'. dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Question 265
A learner is checking dictionary iteration and key membership. What is the exact printed result or uncaught exception?d={"a":1,"b":2}
print(list(d))
- Prints "['a']"
- Prints "['b', 'a']"
- Prints "['a', 'b']"
- Prints "['b']"
Explanation
Correct Answer
C:The snippet prints "['a', 'b']". Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Incorrect Answers
A:This predicts that the snippet prints "['a']", but executing the displayed Python 3 code prints "['a', 'b']". Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
B:This predicts that the snippet prints "['b', 'a']", but executing the displayed Python 3 code prints "['a', 'b']". Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
D:This predicts that the snippet prints "['b']", but executing the displayed Python 3 code prints "['a', 'b']". Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Question 266
A developer tests dictionary iteration and key membership. The following code prints 'false'. Which explanation best accounts for that observed behavior?d={"a":1}
print(1 in d)
- list.insert(i, x) inserts x before position i and shifts later elements rather than replacing them.
- List slicing returns elements from start up to but not including stop; omitted bounds use list ends.
- Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
- 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 'false'; 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 'false'. The relevant Python rule is: Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
B:The list slicing excludes stop topic does not explain why the code prints 'false'. The relevant Python rule is: Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
D:The dictionary get with fallback topic does not explain why the code prints 'false'. The relevant Python rule is: Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Question 267
A learner is checking dictionary iteration and key membership. After this modification, what does Python 3 actually do?d={"x":5,"y":6}
print("y" in d)
- Prints 'False'
- Prints 'True'
- Prints '0'
- Prints '1'
Explanation
Correct Answer
B:The snippetprints 'true'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Incorrect Answers
A:This predicts that the snippet prints 'false', but executing the displayed Python 3 codeprints 'true'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
C:This predicts that the snippet prints '0', but executing the displayed Python 3 codeprints 'true'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
D:This predicts that the snippet prints '1', but executing the displayed Python 3 codeprints 'true'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Question 268
During a review of dictionary iteration and key membership, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
d={"a":1}
print(1 in d)
Program B:
d={"x":5,"y":6}
print("y" in d)
Program C:
d={"a":3,"b":4}
print(sum(d.values()))
- Program B prints 'true'.
- Program A prints 'olleh'.
- Program C prints '7'.
- Program B prints 'none'.
- Program C prints '0'.
- Program A prints 'false'.
Explanation
Correct Answers
A:Running Program Bprints 'true'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
C:Running Program C prints '7'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
F:Running Program A prints 'false'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Incorrect Answers
B:Program A does not produce 'olleh'; its verified result is: Prints 'False'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
D:Program B does not produce 'none'; its verified result is:prints 'True'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
E:Program C does not produce '0'; its verified result is: Prints '7'. Iterating over a dictionary yields keys, and membership using in tests keys rather than values.
Question 269
A learner is checking dictionary items and values. What is the exact printed result or uncaught exception?d={"a":2,"b":3}
print(list(d.items()))
- Prints "[('a', 2), ('b', 3)]"
- Prints "[('b', 3), ('a', 2)]"
- Prints "[('a', 2)]"
- Prints "[('b', 3)]"
Explanation
Correct Answer
A:The snippet prints "[('a', 2), ('b', 3)]". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
Incorrect Answers
B:This predicts that the snippet prints "[('b', 3), ('a', 2)]", but executing the displayed Python 3 code prints "[('a', 2), ('b', 3)]". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
C:This predicts that the snippet prints "[('a', 2)]", but executing the displayed Python 3 code prints "[('a', 2), ('b', 3)]". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
D:This predicts that the snippet prints "[('b', 3)]", but executing the displayed Python 3 code prints "[('a', 2), ('b', 3)]". items yields key/value pairs while values yields values; unpacking pairs preserves their association.
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.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests