Question

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

Option 3 : 4 4

Advertisement

Detailed Solution

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

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

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

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

Correct Answer: 4 4

y = x does not copy the list; both names refer to the same object. Appending through y also changes x, so len(x) is 4 and x[-1] is 4. / y = x सूची की प्रतिलिपि नहीं बनाता; दोनों नाम एक ही ऑब्जेक्ट को दर्शाते हैं।

Downloaded from PrepSnap (prepsnap.in)