Python 3220 Chapter 7

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan 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 or False

True

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] [3, 6] [1, 2] * 3 [1, 2, 1, 2, 1, 2]

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

What will be the value of the variable list2 after the following code executes? [1, 2, 3] Nothing; this code is invalid. [4, 5, 6] [1, 2, 3, 4, 5, 6]

[1, 2, 3]

What values will list2 contain after the following code executes? list1 = [1, 10, 3, 6] list2 = [item * 2 for item in list1 if item > 5] [20, 12] [10, 6] [[1, 10, 3, 6],[1, 10, 3, 6]] [2, 20, 6, 12]

[20, 12]

Which of the following would you use if an element is to be removed from a specific index? a slice method a del statement an index method a remove method

a del statement

This function in the random module returns a random element from a list. random_element choices sample choice

choice

In order to create a graph in Python, you need to include import matplotlib import pyplot import matplotlib.pyplot import matplotlib import pyplot

import matplotlib.pyplot

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

list

The primary difference between a tuple and a list is that a tuple cannot include lists as elements you don't use commas to separate elements in a tuple a tuple can only include string elements once a tuple is created, it cannot be changed

once a tuple is created, it cannot be changed

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

False

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

False

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

False

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

False

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

False

To add a descriptive label to the X and Y axes of a graph when using the matplotlib package, you need to import the labels module. True or False

False

What will be the output after the following code is executed? It will display a simple line graph. Nothing; the number of x-coordinates do not match the number of y-coordinates. Nothing; plt is not a Python method. It will display a simple bar graph.

Nothing; the number of x-coordinates do not match the number of y-coordinates.

What is an advantage of using a tuple rather than a list? Tuples can include any data as an element. Processing a tuple is faster than processing a list. Tuples are not limited in size. There is never an advantage to using a tuple.

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 or False

True

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

True

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

True


Set pelajaran terkait

Chapter 1 - The Human Body: An Orientation

View Set

Sport policy and governance Final exam

View Set

PS470G: The Nominating Process in America

View Set