IN PYTHON: How come you can change elements of a list which is in a tuple and not get an error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

IN PYTHON: How come you can change elements of a list which is in a tuple and not get an error?

28th May 2020, 8:31 AM
Barabbas
Barabbas - avatar
2 Answers
+ 4
tuples holds references to the objects inside but not the objects. so even if the list inside tuple changes the reference to the list doesn't change. You can check it using id() function ex: t = ([1,2,3],3) id(t[0]) doesn't change even if we append or change the contents inside the list.
28th May 2020, 8:47 AM
Aravind Shetty
Aravind Shetty - avatar
+ 2
We can change the value of tuple just write arr in my views for further inquires regarded this Just check it out from here - http://www.openbookproject.net/thinkcs/JUMP_LINK__&&__python__&&__JUMP_LINK/english2e/ch09.html Learning more is necessary for user. Just rock the code🤟🤟
28th May 2020, 8:36 AM
Piyush
Piyush - avatar