0

When we write the following code:

a = [1,2]
b = a
a.append(3)
print(b)

Here, list becomes [1, 2, 3] for both a and b. But when I perform the code:

a=3
b=a
b+=1

Same thing doesn't happen here a=3 and b=4. So, can someone explain to me the reason for this. Also, which data type act as list and which as integer for the same.

melpomene
  • 84,125
  • 8
  • 85
  • 148

1 Answers1

-3

You are assigning the value of a to b so b becomes 3 then again you add 1 in b so the value of b becomes 4.