COSC 1336 - Chapter 7: Lists and Tuples

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

True or 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.

True

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

True

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

True

True or False 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 method can be used to convert a list to a tuple? insert append list tuple

Tuple

Which list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2) [1, 3, 5, 7, 9] [0, 2, 4, 6, 8] [2, 4, 6, 8] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

[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] [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 list after the following code executes? list = [1, 2, 3, 4] list[3] = 10 [1, 10, 10, 10] [1, 2, 10, 4] [1, 2, 3, 10] Nothing; this code is invalid

[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] [4, 5, 6] [1, 2, 3] [1, 2, 3, 4, 5, 6] Nothing; this code is invalid

[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, 4, 5, 6] [1, 2, 3] [4, 5, 6] Error message

[1, 2, 3]

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

[4, 6]

What will the following code display? numbers = [1, 2, 3, 4, 5, 6, 7] print(numbers[4:8]) [4, 5, 6, 7, 8] [5, 6, 7, 8] [5, 6, 7] [1, 2, 3, 4, 5, 6, 7] Error message, because the list does not have an index 8.

[5, 6, 7]

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

a del statement

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

insert

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

once a tuple is created, it cannot be changed

Which method or operator can be used to concatenate lists? + concat * %

+

What are the data items in a list called? items data values elements

Elements

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

False

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

False

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

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

False

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

False

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

False

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

List

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

Processing a tuple is faster than processing a list.


Kaugnay na mga set ng pag-aaral

Chapter 2 Quiz - Electrophysiology

View Set

Raines Semester 2 Exam Quotations (please correct if my answers are wrong)

View Set

Medical Terminology - Module 11: Cardiovascular System

View Set

Chapter 16: Introduction to IP Multicasting

View Set

PA Pediatric EOR, Pediatrics all q

View Set