Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Gaddis Python 2e Chapter 08


 

Download  file with the answers

If you are not a member register here to download this file 


 

Chapter Eight

MULTIPLE CHOICE

1. What are the data items in the list called?
a. data
b. elements
c. items
d. values

2. Which list will be referenced by the variable number after the execution of the following code?
number = range(0, 9, 2)
a. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
b. [1, 3, 5, 7, 9]
c. [2, 4, 6, 8]
d. [0, 2, 4, 6, 8]

3. What would you use if an element is to be removed from a specific index?
a. del statement
b. remove method
c. index method
d. slice method

4. What is the first negative index in a list?
a. 0
b. -1
c. -0
d. Size of the string or list minus one

5. What method can be used to place an item in the list at a specific index?
a. append
b. index
c. insert
d. Add

6. What would be the value of the variable list after the execution of the following code?
list = [1, 2]
list = list * 3
a. [1, 2] * 3
b. [3, 6]
c. [1, 2, 1, 2, 1, 2]
d. [[1, 2], [1, 2], [1, 2]]

7. What would be the value of the variable list after the execution of the following code?
list = [1, 2, 3, 4]
list[3] = 10
a. [1, 2, 3, 10]
b. [1, 2, 10, 4]
c. [1, 10, 10, 10]
d. invalid code

8. What method or operator can be used to concatenate lists?
a. *
b. +
c. %
d. concat

9. What would be the value of the variable list2 after the execution of the following code?
list1 = [1, 2, 3]
list2 = list1
list1 = [4, 5, 6]
a. [1, 2, 3]
b. [4, 5, 6]
c. [1, 2, 3, 4, 5, 6]
d. invalid code

10. What would be the value of the variable list2 after the execution of the following code?
list1 = [1, 2, 3]
list2 = []
for element in list1
list2.append(element)
list1 = [4, 5, 6]
a. [1, 2, 3]
b. [4, 5, 6]
c. [1, 2, 3, 4, 5, 6]
d. invalid code

11. When working with multiple sets of data, one would typically use a(n) _____.
a. list
b. tuple
c. nested list
d. Sequence

12. The primary difference between a tuple and list is that _____.
a. when creating a tuple you don’t use commas to separate elements
b. a tuple can only include string elements
c. a tuple cannot include lists as elements
d. once a tuple is created, it cannot be changed

13. What is the advantage of using tuples over lists?
a. Tuples are not limited in size.
b. Tuples can include any data type as an element.
c. Processing a tuple is faster than processing a list.
d. There is no advantage.

14. What method can be used to convert a list to a tuple?
a. append
b. tuple
c. insert
d. list

15. What method can be used to convert a tuple to a list?
a. append
b. tuple
c. insert
d. list

TRUE/FALSE

1. True/False: Invalid indexes do not cause slicing expressions to raise an exception.

ANS: T

2. True/False: Lists are dynamic data structures such that items may be added to them or removed from them.

ANS: T

3. True/False: Arrays, which most other programming languages allow, have much more capabilities than list structures.

ANS: F

4. True/False: A list cannot be passed as an argument to a function.

ANS: F

5. True/False: The remove method removes all occurrences of the item from a list.

ANS: F

6. True/False: The sort method rearranges the elements of a list so they appear in ascending or descending order.

ANS: F

7. True/False: The first step in calculating the average of the values in a list is to get the total of the values.

ANS: T

8. True/False: Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.

ANS: F

9. True/False: The index – 1 identifies the last element in a list.

ANS: T

10. True/False: In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.

ANS: T

FILL IN THE BLANK

1. A(n) _______________ is an object that holds multiple items of data.

ANS: sequence

2. Each element in a tuple has a(n) _______________ that specifies its position in the tuple.

ANS: index

3. The built-in function _______________ returns the length of a sequence.

ANS: len

4. Tuples are _______________ sequences, which means that once a tuple is created, it cannot be changed.

ANS: immutable

5. A(n) _______________ is a span of items that are taken from a sequence.

ANS: slice

6. Lists are _______________, which means their elements can be changed.

ANS: mutable

7. The _______________ method is commonly used to add items to a list.

ANS: append

8. The _______________ exception is raised when a search item is not in the list being searched.

ANS: ValueError

9. The _______________ method reverses the order of the items in the list.

ANS: reverse

10. The _______________ function returns the item that has the lowest value in the sequence.

ANS: min

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!