a = [1,2,4]
b=a
b.insert(1,45)
print(a,b)
results a = [1,45,2,4] b = [1,45,2,4]
why a is changing is there any way, where b will change
a = [1,2,4]
b=a
b.insert(1,45)
print(a,b)
results a = [1,45,2,4] b = [1,45,2,4]
why a is changing is there any way, where b will change
That's because you're just reassigning the same instance. You need to do this instead of b=a:
b = a.copy()