Professional Documents
Culture Documents
Ibrahim Abou-Faycal
#
EECE-231
#
Introduction to Computation & Programming with Applications
#
Tuples & Lists - Mutable Objects
Reading: [Guttag, Sections 5.1, 5.2, and 5.3] Material in these slides is based on
• Slides of EECE-230C & EECE-230 MSFEA, AUB
• [Guttag, Chapter 5]
Track it on http://www.pythontutor.com/visualize.html
• For a list L without mutable objects, assignment operator L2 = L creates an alias, and L2 =
L.copy() creates a clone
1
2
• For a tuple T without mutable objects, only need the assignment operator T2 = T since
anyways we cannot change T (there is no copy() member function associated with the type
tuple)
• For a list containing mutable objects, assignment operator L2 = L creates an alias, and L2 =
L.copy() creates a clone whose mutable objects are aliases
• For a tuple containing mutable objects, the assignment operator T2 = T creates an alias
• What if we are interested in a deep copy of a list or tuple containing mutable objects: clone
all mutable and immutable objects all the way (i.e., recursively)
Track it on http://www.pythontutor.com/visualize.html
3
4