Python Chapter 6
Suppose that list1 and list2 each reference the same list object in memory. Give a set of instruction that would cause the original list reference to be automatically garbage collected
reassign a different object to list1 and reassign a different object to list2
There are two values associated with an object, its ___________________ value and its ______________________ value
reference, dereferenced
After the following series of assignments are performed, list1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] list2 = list(list1) list2[0][0] = 10 (a) list1[0][0] will equal 1, and list2[0][0] will equal 10 (b) list1[0][0] will equal 10, and list2[0][0] will equal 1 (c) both list1[0][0] and list2[0][0] will equal 10 (d) an error will result (e) id(list1) will equal id(list2)
(c) both list1[0][0] and list2[0][0] will equal 10
For variable n with the value 10, (a) n provides the reference value, and id(n) provides the dereferenced value 10 (b) n provides the value 10 and id(n) provides the value of the location of identifiers n in memory (c) n provides the value 10 and id(n) provides the location of the value 10 in memory (d) n and id(n) are two ways of obtaining the derefereneced value of 10 (e) n and id(n) are two ways of obtaining the reference value of 10
(c) n provides the value 10 and id(n) provides the location of the value 10 in memory
After the following series of assignments are performed, list1 = [1, 2, 3, 4] list2 = list(list1) list1 = [5, 6, 7, 8] (a) list1 will no longer be referencing a list (b) list2 will no longer be referencing a list (c) variable list2 will be referencing the list [5, 6, 7, 8] (d) the list [1, 2, 3, 4] will no longer be referenced by variable list1 or list2 (e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]
(e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]
After the following series of assignments are performed, list1 = [1, 2, 3, 4] list2 = list1 list1 = [5, 6, 7, 8] (a) list1 will no longer be referencing a list (b) list2 will no longer be referencing a list (c) variable list2 will be referencing the list [5, 6, 7, 8] (d) the list [1, 2, 3, 4] will no longer be referenced by variable list1 or list2 (e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]
(e) list1 will reference the list [5, 6, 7, 8] and list2 will reference the list [1, 2, 3, 4]
An object contains a set of __________________ and a set of ____________
attributes, functions
Build in function _______ can be used in Python to determine if two variables reference the same object in memory
id()
Suppose that list1 is assigned to a list of tuples. Given the proper code so that a complete copy of list1 is assigned to variable list2
import copy List2=copy.deepcopy(list1)
Suppose that variable k is assigned to a list object that contains a method called numZeros that returns the number of 0 values in the list. Give the proper syntax for calling method numZeros on variable k
k.numZeros()
Give Python code to determine if two lists, list1 and list2, reference two completely different list objects or not
list1 is list2
Suppose that list1 is assigned to a list of integers. Given the proper code so that a complete copy of list1 is assigned to variable list2
list2=list(list1)
Examine the following Python code list1 = [1, 2, 3, 4, 5] list2 = list1 list1.append(6) list2.append(7) for i in list1: print(i, end = '') print() for i in list2: print(i, end = '') What will this code output? Explain
1234567 and 1234567 because list2 is pointing to the same object in memory as list 1 so whenever one changes the other does too
The _____________ is used to access a member of an object
dot operator
