Programming Languages
Python
Subjective
Sep 30, 2025
What is the output of the following code?\n```python\nx = [1, 2, 3]\ny = x\ny.append(4)\nprint(x)\n```
Detailed Explanation
Output: [1, 2, 3, 4]\nBoth x and y reference the same list object. Modifying y also affects x because lists are mutable and passed by reference.
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts