100% Latest & Updated Python Institute PCEP-30-02 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
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.
Question 281
A learner is checking split and join strings. What is the exact printed result or uncaught exception?print("red,blue".split(","))
- Prints "['red', 'blue']"
- Prints "['red']"
- Prints "['blue', 'red']"
- Prints "['blue']"
Explanation
Correct Answer
A:The snippet prints "['red', 'blue']". split converts a string to parts using a delimiter; join combines string parts with a separator.
Incorrect Answers
B:This predicts that the snippet prints "['red']", but executing the displayed Python 3 code prints "['red', 'blue']". split converts a string to parts using a delimiter; join combines string parts with a separator.
C:This predicts that the snippet prints "['blue', 'red']", but executing the displayed Python 3 code prints "['red', 'blue']". split converts a string to parts using a delimiter; join combines string parts with a separator.
D:This predicts that the snippet prints "['blue']", but executing the displayed Python 3 code prints "['red', 'blue']". split converts a string to parts using a delimiter; join combines string parts with a separator.
Question 282
A developer tests split and join strings. The following code prints 'a-b-c'. Which explanation best accounts for that observed behavior?parts=["a","b","c"]
print("-".join(parts))
- Two names pointing to the same list share mutations, while a slice copy creates a new outer list.
- 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.
- dict.get(key, default) returns the default for a missing key, unlike direct subscription.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints 'a-b-c'; 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 'a-b-c'. The relevant Python rule is: split converts a string to parts using a delimiter; join combines string parts with a separator.
C:The del and list slice deletion topic does not explain why the code prints 'a-b-c'. The relevant Python rule is: split converts a string to parts using a delimiter; join combines string parts with a separator.
D:The dictionary get with fallback topic does not explain why the code prints 'a-b-c'. The relevant Python rule is: split converts a string to parts using a delimiter; join combines string parts with a separator.
Question 283
A learner is checking split and join strings. After this modification, what does Python 3 actually do?print("a b".split())
- Prints "['a']"
- Prints "['b']"
- Prints "['b', 'a']"
- Prints "['a', 'b']"
Explanation
Correct Answer
D:The snippet prints "['a', 'b']". split converts a string to parts using a delimiter; join combines string parts with a separator.
Incorrect Answers
A:This predicts that the snippet prints "['a']", but executing the displayed Python 3 code prints "['a', 'b']". split converts a string to parts using a delimiter; join combines string parts with a separator.
B:This predicts that the snippet prints "['b']", but executing the displayed Python 3 code prints "['a', 'b']". split converts a string to parts using a delimiter; join combines string parts with a separator.
C:This predicts that the snippet prints "['b', 'a']", but executing the displayed Python 3 code prints "['a', 'b']". split converts a string to parts using a delimiter; join combines string parts with a separator.
Question 284
During a review of split and join strings, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
parts=["a","b","c"]
print("-".join(parts))
Program B:
print("a b".split())
Program C:
print("".join(["x","y"]))
- Program B prints "['a', 'b']".
- Program C prints '[]'.
- Program A prints 'false'.
- Program A prints 'a-b-c'.
- Program C prints 'xy'.
- Program B prints '[15, 9, 3]'.
Explanation
Correct Answers
A:Running Program B prints "['a', 'b']". split converts a string to parts using a delimiter; join combines string parts with a separator.
D:Running Program A prints 'a-b-c'. split converts a string to parts using a delimiter; join combines string parts with a separator.
E:Running Program C prints 'xy'. split converts a string to parts using a delimiter; join combines string parts with a separator.
Incorrect Answers
B:Program C does not produce '[]'; its verified result is: Prints 'xy'. split converts a string to parts using a delimiter; join combines string parts with a separator.
C:Program A does not produce 'false'; its verified result is: Prints 'a-b-c'. split converts a string to parts using a delimiter; join combines string parts with a separator.
F:Program B does not produce '[15, 9, 3]'; its verified result is: Prints "['a', 'b']". split converts a string to parts using a delimiter; join combines string parts with a separator.
Question 285
A learner is checking find replace and count methods. What is the exact printed result or uncaught exception?print("banana".find("na"))
- Prints '2'
- Prints '1'
- Prints '3'
- Prints '4'
Explanation
Correct Answer
A:The snippet prints '2'. String methods such as find, replace and count return information or new strings without mutating the original.
Incorrect Answers
B:This predicts that the snippet prints '1', but executing the displayed Python 3 code prints '2'. String methods such as find, replace and count return information or new strings without mutating the original.
C:This predicts that the snippet prints '3', but executing the displayed Python 3 code prints '2'. String methods such as find, replace and count return information or new strings without mutating the original.
D:This predicts that the snippet prints '4', but executing the displayed Python 3 code prints '2'. String methods such as find, replace and count return information or new strings without mutating the original.
Question 286
A developer tests find replace and count methods. The following code prints '3'. Which explanation best accounts for that observed behavior?print("banana".count("a"))
- list.insert(i, x) inserts x before position i and shifts later elements rather than replacing them.
- 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.
- A tuple does not support item assignment; rebinding a tuple variable does not mutate the original tuple.
Explanation
Correct Answer
C:This is the operative language rule for the code. It directly explains why the example prints '3'; 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 '3'. The relevant Python rule is: String methods such as find, replace and count return information or new strings without mutating the original.
B:The negative list indices topic does not explain why the code prints '3'. The relevant Python rule is: String methods such as find, replace and count return information or new strings without mutating the original.
D:The tuple immutability topic does not explain why the code prints '3'. The relevant Python rule is: String methods such as find, replace and count return information or new strings without mutating the original.
Question 287
A learner is checking find replace and count methods. After this modification, what does Python 3 actually do?s="abba"
print(s.replace("b","x"),s)
- Prints 'axxa abba'
- Prints 'abba axxa'
- Prints 'axxa abb'
- Prints 'axxa abba?'
Explanation
Correct Answer
A:The snippet prints 'axxa abba'. String methods such as find, replace and count return information or new strings without mutating the original.
Incorrect Answers
B:This predicts that the snippet prints 'abba axxa', but executing the displayed Python 3 code prints 'axxa abba'. String methods such as find, replace and count return information or new strings without mutating the original.
C:This predicts that the snippet prints 'axxa abb', but executing the displayed Python 3 code prints 'axxa abba'. String methods such as find, replace and count return information or new strings without mutating the original.
D:This predicts that the snippet prints 'axxa abba?', but executing the displayed Python 3 code prints 'axxa abba'. String methods such as find, replace and count return information or new strings without mutating the original.
Question 288
During a review of find replace and count methods, three independent Python 3 fragments are shown. Which THREE statements accurately describe their behavior? (Choose THREE.)Program A:
print("banana".count("a"))
Program B:
s="abba"
print(s.replace("b","x"),s)
Program C:
print("cat".find("z"))
- Program A prints '2'.
- Program C prints 'xy'.
- Program B prints 'axxa abba'.
- Program A prints '3'.
- Program B prints '([4, 9],)'.
- Program C prints '-1'.
Explanation
Correct Answers
C:Running Program B prints 'axxa abba'. String methods such as find, replace and count return information or new strings without mutating the original.
D:Running Program A prints '3'. String methods such as find, replace and count return information or new strings without mutating the original.
F:Running Program C prints '-1'. String methods such as find, replace and count return information or new strings without mutating the original.
Incorrect Answers
A:Program A does not produce '2'; its verified result is: Prints '3'. String methods such as find, replace and count return information or new strings without mutating the original.
B:Program C does not produce 'xy'; its verified result is: Prints '-1'. String methods such as find, replace and count return information or new strings without mutating the original.
E:Program B does not produce '([4, 9],)'; its verified result is: Prints 'axxa abba'. String methods such as find, replace and count return information or new strings without mutating the original.
Question 289
A learner is checking function return controls result. What is the exact printed result or uncaught exception?def double(x):
return 2*x
print(double(4))
- Prints '7'
- Prints '8'
- Prints '9'
- Prints '10'
Explanation
Correct Answer
B:The snippet prints '8'. A return statement immediately exits a function and supplies its expression as the call result.
Incorrect Answers
A:This predicts that the snippet prints '7', but executing the displayed Python 3 code prints '8'. A return statement immediately exits a function and supplies its expression as the call result.
C:This predicts that the snippet prints '9', but executing the displayed Python 3 code prints '8'. A return statement immediately exits a function and supplies its expression as the call result.
D:This predicts that the snippet prints '10', but executing the displayed Python 3 code prints '8'. A return statement immediately exits a function and supplies its expression as the call result.
Question 290
A developer tests function return controls result. The following code prints 'other'. Which explanation best accounts for that observed behavior?def f(n):
if n>0: return "pos"
return "other"
print(f(-1))
- Assigning to a name anywhere in a function makes it local unless declared global; reading it first raises UnboundLocalError.
- A return statement immediately exits a function and supplies its expression as the call result.
- Providing a parameter both positionally and by keyword causes TypeError for multiple values.
- A generator can yield one value per loop pass, and consumption determines how many iterations run.
Explanation
Correct Answer
B:This is the operative language rule for the code. It directly explains why the example prints 'other'; the displayed behavior was independently reproduced by a Python 3 execution check.
Incorrect Answers
A:The local variable before assignment error topic does not explain why the code prints 'other'. The relevant Python rule is: A return statement immediately exits a function and supplies its expression as the call result.
C:The duplicate argument assignment raises TypeError topic does not explain why the code prints 'other'. The relevant Python rule is: A return statement immediately exits a function and supplies its expression as the call result.
D:The yield inside for loop topic does not explain why the code prints 'other'. The relevant Python rule is: A return statement immediately exits a function and supplies its expression as the call result.
PCEP - Certified Entry-Level Python Programmer (PCEP-30-02) Practice Tests