0

I have read that tuples are immutable. But this works fine:

t=(1,[2,3,4])
t[1][1]=9

Also, I tried printing their id to see whether their ids are different as suggested in this question, but they are the same.

So I am confused, can someone please explain this behavior?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
cheems
  • 164
  • 7
  • Are you mutating the tuple or the array? Try `t[1] = 9 ` – JonSG Dec 26 '21 at 03:03
  • @JonSG mutaing the array which is an element of tuple. – cheems Dec 26 '21 at 03:08
  • 2
    The immutability applies to the tuple itself (you cannot change its elements, ex. `t[1] = 9`) but not to its individual elements which can be mutable. – Gino Mempin Dec 26 '21 at 03:22
  • @GinoMempin Thanks for the linked question, my query is resolved because of it, I was unable to find it neither it was suggested while posting question. – cheems Dec 26 '21 at 03:31

0 Answers0