Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 2 : 3

Advertisement

Detailed Solution

सही उत्तर 3 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following Python code? a = (1, 2, 3); b = a; b += (4,); print(len(a)) / निम्नलिखित Python कोड का आउटपुट क्या है?

1.
4
2.
3
3.
Error
4.
1

Correct Answer: 3

Tuples are immutable, so b += (4,) rebinds b to a NEW tuple (1, 2, 3, 4) instead of modifying a. Hence len(a) stays 3. / टपल अपरिवर्तनीय है, अतः b += (4,) से b नए टपल से जुड़ता है; a अपरिवर्तित रहता है।

Downloaded from PrepSnap (prepsnap.in)