Deck 6: Objects and Their Use
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/54
Play
Full screen (f)
Deck 6: Objects and Their Use
1
An object consists of functions, called methods, that operate on the data contained within the object.
True
2
All values in Python are represented as objects.
True
3
Objects consist of three fundamental parts: a set of attributes, a set of non-value returning functions called methods, and a set of value-returning functions.
False
4
The dot operator is used to select a member of an object.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
5
Two objects of the same type have the same set of methods.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
6
Two objects of the same type store the same set of values, but are represented by instance variables with different identifiers (names) in each.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
7
A list in Python is a collection of objects (values), but the list itself is not an object.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
8
A list in Python contains a collection of values, in which each value is an object, but the list itself is not an object.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
9
There may be more than on name associated with a given object stored in memory.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
10
Built-in function id can be used to obtain the reference value of any object in Python.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
11
Built-in function id return a unique value for all objects in Python.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
12
When one variable is assigned to another, it is the dereferenced value that is assigned, not the reference value.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
13
To deallocate a memory location is to mark it as "no longer needed" so that the executing program does not attempt to use it.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
14
Garbage collection it a process that automatically determines what parts of memory can be deallocated during the execution of a program.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
15
When one variable is assigned to another variable referencing a list, a second copy of the list is automatically created.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
16
Python provides a list contructor that can be used to create a deep copy of a list.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
17
In Python, an object has certain attributes and behaviors, implemented as
A) functions and methods
B) instance variables and methods
C) instance variables and values
D) lists and methods
E) lists and values
A) functions and methods
B) instance variables and methods
C) instance variables and values
D) lists and methods
E) lists and values
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
18
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
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
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
19
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 [5, 6, 7, 8]
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 [5, 6, 7, 8]
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
20
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 [5, 6, 7, 8]
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 [5, 6, 7, 8]
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
21
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)
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)
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
22
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)
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)
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
23
Match the following:
-behavior
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
-behavior
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
24
Match the following:
-memory deallocation
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
-memory deallocation
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
25
Match the following:
-memory location
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
-memory location
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
26
Match the following:
-attribute
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
-attribute
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
27
Match the following:
-selection
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
-selection
A) instance variable
B) method
C) dot operator
D) reference
E) garbage collection
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
28
An object contains a set of __________________ and a set of ____________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
29
The _____________ is used to access a member of an object.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
30
There are two values associated with an object, its ___________________ value and its_____________________ value.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
31
Build in function _______ can be used in Python to determine if two variables reference the same object in memory.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
32
There are two types of creating a copy of an object, a ___________ copy and a _____________ copy..
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
33
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.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
34
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.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
35
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.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
36
Give Python code to determine if two lists, list1 and list2, reference two completely different list objects or not.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
37
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.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
38
Examine the following Python code:
list1 = [1, 2, 3, 4, 5]
list2 = nList
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.
list1 = [1, 2, 3, 4, 5]
list2 = nList
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.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
39
The use of turtle graphics in Python requires that the turtle module be imported.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
40
A location in the turtle graphics window is indicated by an x and y coordinate value relative to the center of the screen in inches.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
41
For a turtle screen size of 600 x 800, the coordinates of the top left corner are (-300, 400).
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
42
The can be created numerous turtle objects in a given program.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
43
When a turtle is moved to a new position using the setposition method, a line is drawn from its current location to the new location if the turtle is set to be shown (by use of the showturtle method.)
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
44
What would the result of the turtle.setup(400, 500) be in turtle graphics?
A) A turtle screen of 400 pixels wide and 500 pixels high would be created.
B) A turtle screen of 500 pixels wide and 400 pixels high would be created.
C) A turtle screen of -400 to 400 pixels wide and -500 to 500 pixels high would be created.
D) A turtle screen of -500 to 500 pixels wide and -400 to 400 pixels high would be created.
E) None of the above
A) A turtle screen of 400 pixels wide and 500 pixels high would be created.
B) A turtle screen of 500 pixels wide and 400 pixels high would be created.
C) A turtle screen of -400 to 400 pixels wide and -500 to 500 pixels high would be created.
D) A turtle screen of -500 to 500 pixels wide and -400 to 400 pixels high would be created.
E) None of the above
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following returns the reference to the "default" turtle created as a result of a call to the setup method?
A) window.turtle()
B) window.getTurtle()
C) setup.getTurtle()
D) setup.getturtle()
E) turtle.getturtle()
A) window.turtle()
B) window.getTurtle()
C) setup.getTurtle()
D) setup.getturtle()
E) turtle.getturtle()
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following is NOT an example of relative positioning?
A) the_turtle.setposition(100, 100)
B) the_turtle.forward(100)
C) the_turtle.left(90)
D) the_turtle.penup()
E) the_turtle.hideturtle()
A) the_turtle.setposition(100, 100)
B) the_turtle.forward(100)
C) the_turtle.left(90)
D) the_turtle.penup()
E) the_turtle.hideturtle()
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
47
The __________ method of turtle graphics in Python is used to create a turtle screen of a specific size.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
48
The instruction to get the reference to the "default" turtle in turtle graphics is __________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
49
The instruction to set the position of a turtle object to the center of the screen is __________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
50
The instruction to determine the current position of a turtle object is __________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
51
The instruction to create a new turtle object is ____________________________.
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
52
Give Python code to create a square of size 100 x 100 such that its bottom left corner is positioned at screen location (0, 0). Use absolute positioning to do this. (Assume that the turtle screen has been set up, and that there is a turtle named the_turtle to make use of.)
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
53
Give Python code to create a square of size 100 x 100 such that its bottom left corner is positioned at screen location (0, 0). Use relative positioning to do this. (Assume that the turtle screen has been set up, and that there is a turtle named the_turtle to make use of.)
Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck
54
Give Python code using turtle graphics that draws three squares, one inside of the other as shown below.


Unlock Deck
Unlock for access to all 54 flashcards in this deck.
Unlock Deck
k this deck