Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 2 : abc abcd / abc abcd
Advertisement
Detailed Solution
सही उत्तर abc abcd / abc abcd है।
Key Points
Helpful?
Question:
What is the output of the following Python code involving string immutability with +=? / += के साथ स्ट्रिंग अपरिवर्तनीयता वाले निम्नलिखित Python कोड का आउटपुट क्या होगा? s1 = "abc" s2 = s1 s1 += "d" print(s2, s1)
1.
abcd abcd / abcd abcd
2.
abc abcd / abc abcd
3.
abc abc / abc abc
4.
TypeError / TypeError
Correct Answer: abc abcd / abc abcd
Strings are immutable, so s1 += "d" creates a new string bound to s1 while s2 still refers to the original "abc". / स्ट्रिंग अपरिवर्तनीय हैं, इसलिए s1 += "d" एक नई स्ट्रिंग बनाकर s1 से बाँधता है, जबकि s2 मूल "abc" की ओर ही इशारा करता है।
Downloaded from PrepSnap (prepsnap.in)