Question
Option 2 : `([1, 2, 5], [3, 4])` / `([1, 2, 5], [3, 4])`
Detailed Solution
सही उत्तर `([1, 2, 5], [3, 4])` / `([1, 2, 5], [3, 4])` है।
Question:
What happens when the following Python code executes? `t = ([1, 2], [3, 4])` / `try:` / ` t[0] += [5]` / `except TypeError:` / ` pass` / `print(t)` / निम्नलिखित Python कोड निष्पादित होने पर क्या होता है? `t = ([1, 2], [3, 4])` / `try:` / ` t[0] += [5]` / `except TypeError:` / ` pass` / `print(t)`
Correct Answer: `([1, 2, 5], [3, 4])` / `([1, 2, 5], [3, 4])`
Augmented assignment `t[0] += [5]` first calls the list's in-place `__iadd__`, mutating `t[0]` to `[1, 2, 5]`, and only then attempts the item assignment back into the tuple — which raises TypeError because tuples are immutable. The mutation already happened, so the except block swallows the error and `print(t)` shows `([1, 2, 5], [3, 4])`. The trap is assuming that a TypeError leaves everything unchanged. / संवर्धित असाइनमेंट `t[0] += [5]` पहले list के in-place `__iadd__` को कॉल करता है, जिससे `t[0]` बदलकर `[1, 2, 5]` हो जाता है, और उसके बाद ही tuple में आइटम असाइनमेंट का प्रयास करता है — जो TypeError उठाता है क्योंकि tuple अपरिवर्तनीय है। परिवर्तन पहले ही हो चुका है, अतः except ब्लॉक त्रुटि को दबा देता है और `print(t)` से `([1, 2, 5], [3, 4])` दिखता है। जाल यह मानना है कि TypeError आने पर कुछ भी नहीं बदलता।