Starting Out with Python Chapter 7

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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,)

This built-in function returns the highest value in a list. a. highest b. max c. greatest d. best of

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)

mylist.insert(0, 'Labrador')

This file object method returns a list containing the file's contents. a. to_list b. getlist c. readline d. readlines

readlines

This removes an item at a specific index in a list. a. the remove method b. the delete method c. the del statement d. the kill method

the del statement

You can use the + operator to concatenate two lists. T or F

True

This list method adds an item to the end of an existing list. a. add b. add to c. increase d. append

append

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. An IndexError exception will occur. c. The list will be erased and the program will continue to run. d. Nothing-the invalid index will be ignored.

An IndexError exception will occur.

A file object's writelines method automatically writes a newline ( '\n' ) after writing each list item to the file. T or F

False

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

False

Lists in Python are immutable. T or F

False

You can remove an element from a tuple by calling the tuple's remove method. T or F

False

This is the first index in a list. a. - 1 b. 1 c. 0 d. The size of the list minus one

0

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. An Invalidindex exception is raised. c. The method returns - 1. d. Nothing happens. The program continues running at the next statement.

A ValueError exception is raised.

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.

The repetition operator

This is the last index in a list. a. 1 b. 99 c. 0 d. The size of the list minus one

The size of the list minus one

A list can be an element in another list. T or F

True

The del statement deletes an item at a specified index in a list. T or F

True

Tuples in Python are immutable. T or F

True

This term refers to an individual item in a list. a. element b. bin c. cubbyhole d. slot

element

This is a number that identifies an item in a list. a. element b. index c. bookmark d. identifier

index

This function returns the length of a list. a. length b. size c. len d. lengthof

len


Set pelajaran terkait

Peds Test 1 (Ch. 1, 3, 4, 5, 10, 12, 13, 15, 17, 19, 20, 21, 22, & 23)

View Set

The Rational Roots Theorem Assignment

View Set

Career Exam One - Ability and Aptitude Assessment in Career Counseling

View Set

Computer Programming Chapter 4 Review

View Set