COMP10001 Final: Meaning of mutability and its type

69 views2 pages
Meaning of mutability and its type
The possibility to change
tuple is immutable
o >>> a = (4,5,6)
o >>> a[1] = 99
o >>> error!
list is mutable
o >>> a = [4, 5, 6]
o >>> a[1] = 99
o >>> print (a)
o >>> [4, 99, 6]
integers are immutable
o
o it appears not maybe we could change integers, but the id changes when we
try to do that
o which means instead of changing values of object, we changed the object
Mutables inside immutables
What if to change a list within a tuple? only the list part is mutable
because the “id” of tuple cannot be changed, we can change the list part of it because
we don’t change the tuple value
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents

Related Questions