0

I am doing this simple thing, but I don't expect the right operand (apples) to be modified when I modify the left operand(bananas).

>> apples = [1,2,3,4,5]
>> bananas = apples
>> bananas.remove(3)
>> bananas 
   [1,2,4,5]
>> apples 
   [1,2,4,5]

apples should be [1,2,3,4,5] instead of [1,2,4,5].

Please comment on this.

Regards.

user189942
  • 351
  • 1
  • 3
  • 12

1 Answers1

1

Simplest way avoid it use:

bananas = []+apples
mmachine
  • 896
  • 6
  • 10