Programming CHP 7

¡Supera tus tareas y exámenes ahora con Quizwiz!

To calculate the average of the numeric values in a list, the first step is to get the total of values in the list.

True

Which list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2)

[0, 2, 4, 6, 8]

What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3

[1, 2, 1, 2, 1, 2]

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10

[1, 2, 3, 10]

What will be the value of the variable list2 after the following code executes? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6]

[1, 2, 3]

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]

[1, 2, 3]

What will the following code display? values = [2, 4, 6, 8, 10] print(values[1:3])

[4, 6]

What will the following code display? numbers = [1, 2, 3, 4, 5, 6, 7] print(numbers[4:8])

[5, 6, 7]

Which of the following would you use if an element is to be removed from a specific index?

a del statement

What are the data items in a list called?

elements

Which method can be used to place an item at a specific index in a list?

insert

Which method can be used to convert a tuple to a list?

list

The primary difference between a tuple and a list is that

once a tuple is created, it cannot be changed

Which method can be used to convert a list to a tuple?

tuple

Which method or operator can be used to concatenate lists?

+

A list cannot be passed as an argument to a function.

False

Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures.

False

Assume list1 references a list. After the following statement is executed, list1 and list2 will reference two identical, but separate lists in memory: list2 = list1

False

The index of the first element in a list is 1, the index of the second element is 2, and so forth.

False

The remove method removes all occurrences of an item from a list.

False

The sort method rearranges the elements of a list so they are in ascending or descending order.

False

What is an advantage of using a tuple rather than a list?

Processing a tuple is faster than processing a list.

In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.

True

Invalid indexes do not cause slicing expressions to raise an exception.

True

Lists are dynamic data structures such that items may be added to them or removed from them.

True


Conjuntos de estudio relacionados

Searching, Sorting, Concurrency, and Threads

View Set

Ch. 66: Management of Patients with Neurologic Dysfunction

View Set

Study Guide - Intro To Operating Systems - Chapter 10 - Connecting Desktops and Laptops to Networks Quiz

View Set