Chapter 7 - Review
( T / F ) A files object's *writelines* method automatically writes a newline ('\n') after writing each list item to the file
F
( T / F ) Assume list1 references a list. After the following statement executes, list1 and list2 will reference two identical but separate lists in memory: list2 = list1
F
( T / F ) Lists in python are immutable
F Lists in python are mutable
( T / F ) In python, the index of the first element of the list is 1
F [0]
( T / F ) Invalid indexes in slicing expressions can produce an 'out of bound' exception
F slicing can never cause 'out of bounds' exceptions
( T / F ) A list can be an element in another list
T
( T / F ) The *del* statement deletes an item at a specified index in a list
T
( T / F ) Tuples in python are immutable
T
If you call the *index* method to locate an item in a list and the item is not found, this happens a. a *ValueError* exception is raised b. a *IndexError* exception is raised c. the method return -1 d. nothing happens--the program continue running at the next statement
a. a *ValueError* exception is raised
This term refers to an individual item in a list. a. element b. bin c. cubbyhole d. slot
a. element
The method used to write an entire list to a file is known as a. writelines b. writeline c. writelists d. writelist
a. writelines
This will happen if you try to use an index that is out of range for a list a. a *ValueError* exception will occur b. a *IndexError* exception will occur c. this list will be erased and the program will continue to run d. nothing--the invalid index will be ignored
b. a *IndexError* exception will occur
This is a number that qualifies an item in a list. a. element b. index c. bookmark d. identifier
b. index
When the * operator's left operand is a list and its right operand is an integer, the operator becomes this. a. the multiplication operator b. the repetition operator c. the initialization operator d. nothing--the operator does not support those types of operands
b. the repetition operator
Which of the following is not a property of tuples? a. tuples are immutable data structures b. tuples do not support functions like len, min, max c. tuples can be accessed just like lists d. processing tuples is faster than lists
b. tuples do not support functions like len, min, max
This built-in function returns the highest value in a list. a. minimumOf() b. minimum() c. max() d. least()
c. max()
Assume the following statement appears in a program: mylist = [] Which of the following statements would you use to add the string 'Labrador' to the list at index 0? a. mylist[0]= 'Labrador' b. mylist.insert(0, 'Labrador') c. mylist.append('Labrador') d. mylist.insert('Labrador', 0)
c. mylist.append('Labrador')
This list method adds an item to the end of an existing list. a. add b. add_to c. increase d. append
d. append
In Python, lists are a. a mutable data structures b. static data structures c. dynamic data structures d. both a & c
d. both a & c
This file object method returns a list containing the file's contents. a. to_list b. getlist c. readline d. readlines
d. readlines
This is the last index in the list a. 1 b. 99 c. 0 d. the size of the list minus one
d. the size of the list minus one
Which of the following statements creates a tuple? a. values = [1, 2, 3, 4] b. values = {1, 2, 3, 4} c. values = (1) d. values = (1, )
values = (1,)