+ 3

Can someone explain the solution for below question ?

What is the output of below code ? a=[1,[2,3]] b=a[:] a[1][1] = 5 a[0] = 3 print[b] I was expecting [3,[2,5]] as the output. But the actual answer is [1,[2,5]].

15th Apr 2019, 6:47 AM
N Rajesh
N Rajesh - avatar
10 odpowiedzi
+ 5
b creates a deep copy of 'a', except a[1], where the reference is the one copied. Therefore, affecting a[1] affects b[1] while it does not apply for a[0] and b[0]
15th Apr 2019, 7:27 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
15th Apr 2019, 7:31 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
What is the output of this code? a = {1, 2, 3} b = {0, 3, 4, 5} print(a & b) Ans: print a & b i.e the number which are present in both set a and set b output: 3
6th Dec 2020, 4:24 AM
IRFAN KHAN
IRFAN KHAN - avatar
+ 3
Thank you for answering 😀 Can you suggest me some site for refernce or please provide in detail about that except you mentioned. Thank you in advance
15th Apr 2019, 7:31 AM
N Rajesh
N Rajesh - avatar
+ 3
a=[1,[2,3]] b=a[:] a[1][1] = 5 b[0] = 3 print(b) hey Rajesh, at second last line you are assigning a new value to a' instead assign it to b
15th Apr 2019, 7:32 AM
Deepak Dhage
+ 3
The b wont change until it got declared. a = 10 b = a*2 #b is 20 a = 20 #b is still 20 maybe, this helped.👀🔥
15th Apr 2019, 5:49 PM
I‘m Sarah🌹
I‘m Sarah🌹 - avatar
+ 1
Thank you promethesus and Deepak.
15th Apr 2019, 7:37 AM
N Rajesh
N Rajesh - avatar
0
What is the output of this code? a = {1, 2, 3} b = {0, 3, 4, 5} print(a & b) output:3
28th Apr 2020, 4:14 AM
makhan Kumbhkar
makhan Kumbhkar - avatar
0
answer is 3
24th Jul 2021, 6:11 AM
Judson Leo
Judson Leo - avatar
0
the answer is {3} and not just 3
10th Oct 2023, 11:52 AM
Samruddhi Gawande
Samruddhi Gawande - avatar