Find the output of the following Python code: def StringTwist(STR, L): STR =…
2026
Find the output of the following Python code:
def StringTwist(STR, L):
STR = STR.title()
L[0] *= 2; L[1] += L[0]
L.append(STR)
print("Twist String:", STR) # Output 2A
print("List:", L) # Output 2B
TEXT = "peace park"
VAL = [5, 10]
StringTwist(TEXT, VAL)
VAL[0] *= 5
print("String:", TEXT) # Output 2C
print("List:", VAL) # Output 2D
Attempted by 9 students.
Show answer & explanation
In function
StringTwist(STR, L),STRis immutable (string) whileLis mutable (list).STR = STR.title()⇒"peace park"becomes"Peace Park"(only local change).L[0] *= 2⇒[5, 10] → [10, 10]L[1] += L[0]⇒[10, 10] → [10, 20]L.append(STR)⇒[10, 20, "Peace Park"]Outputs inside function:
Twist String: Peace Park
List: [10, 20, 'Peace Park']
After function call:
VAL[0] *= 5⇒[10, 20, 'Peace Park'] → [50, 20, 'Peace Park']Final outputs:
String: peace park
List: [50, 20, 'Peace Park']