What is the expected output?
MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What is the expected output?**
math_constants = [3.1416, 1.618, 2.7183, 0.57721]
Return = math_constants.append(1.30357)
print(math_constants)
print(Return)
Pick ONE option
Show answer & explanation
Answer: C. [3.1416, 1.618, 2.7183, 0.57721, 1.30357]
None
The list.append() method modifies the list in-place and returns None, not the modified list. After executing append(1.30357), the math_constants list is modified to include the new element. When Return is assigned the result of append(), it receives None. Therefore, print(math_constants) outputs the updated list, and print(Return) outputs None.
Step-by-step Derivation:
Step-by-step execution:
- math_constants is initialized as [3.1416, 1.618, 2.7183, 0.57721]
- math_constants.append(1.30357) modifies the list in-place to [3.1416, 1.618, 2.7183, 0.57721, 1.30357] and returns None
- Return = None (the return value of append)
- print(math_constants) outputs: [3.1416, 1.618, 2.7183, 0.57721, 1.30357]
- print(Return) outputs: None