Starting out with Python Chapter 7

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/88

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:37 AM on 7/23/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

89 Terms

1
New cards

A ___________ is an object that holds multiple items of data, stored one after the other. You can perform operations on a sequence to examine and manipulate the items stored in it.

sequence

2
New cards

A _______ is mutable: the program can change it's contents.

list

3
New cards

A ________ is immutable: once created, the contents cannot be changed

tuple

4
New cards

Lists are dynamic data structures, meaning that items may be added or removed from them. (True or False)

True

5
New cards

Each item in a list is called a(n) __________.

element

6
New cards

even_numbers = [2, 4, 6, 8, 10]

is an example of what?

list

7
New cards

A list can hold items of different types? (True or False)

True

8
New cards

Is the code below representative of a repetition operator?

num = [1, 2, 3]

x = 5

num * x

yes

9
New cards

A _______________ makes multiple copies of a list and joins them all together.

repetition operator

10
New cards

You can iterate over a list with a for loop? (True or False)

True

11
New cards

Each element in a list has a ________ that specifies its' position in the list.

index

12
New cards

What number does indexing start at?

0

13
New cards

What number would the final term in a list be indexed at?

The number of items in the list minus 1.

14
New cards

You can't use negative indexes to reference elements in a list. (True or False)

False

15
New cards

An ____________ will be raised when you use an invalid index with a list.

IndexError

16
New cards

What value will the following code return?

my_list = [a, b, c, d, e, f]

size = len(my_list)

6

17
New cards

What is the output of the following code?

list1 = [a, b, c]

list2 = [d, e, f]

list3 = list1 + list2

print(list3)

[a, b, c, d, e, f]

18
New cards

What is the value of list1 after the following code?

list1 = [a, b]

list2 = [c, d]

list += list2

[a, b, c, d]

19
New cards

You can concatenate lists with any other type of data. (True or False)

False

20
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

numbers[2] = 99

print(numbers)

[1, 2, 99, 4, 5]

21
New cards

What will the following code display?

numbers = list(range(3))

print(numbers)

[ 0, 1, 2]

22
New cards

What will the following code display?

numbers = [10] * 5

print(numbers)

[10, 10, 10, 10, 10]

23
New cards

What will the following code display?

numbers = list(range(1, 10, 2))

for n in numbers:

print(n)

1

3

5

7

9

24
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

print(numbers[-2])

4

25
New cards

How do you find the number of elements in a list?

Using the len() function.

26
New cards

What will the following code display?

numbers1 = [1, 2, 3]

numbers2 = [10, 20, 30]

numbers3 = numbers1 + numbers2

print(numbers1)

print(numbers2)

print(numbers3)

[1, 2, 3]

[10, 20, 30]

[1, 2, 3, 10, 20, 30]

27
New cards

What will the following code display?

numbers1 = [1, 2, 3]

numbers2 = [10, 20, 30]

numbers2 += numbers1

print(numbers1)

print(numbers2)

[1, 2, 3]

[10, 20, 30, 1, 2, 3]

28
New cards

A ________ is a span of items that are taken from a sequence.

slice

29
New cards

What prints out in the following code?

days = [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]

mid_days = days[2:5]

print(mid_days)

['Tuesday', 'Wednesday', 'Thursday']

30
New cards

The first element of a list is what number index?

0

31
New cards

In the example below, what will print out?

li = [1, 2, 3, 5]

li_section = li[1:3]

print(li_section)

[2, 3]

32
New cards

If you leave out the start index when slicing an expression, Python uses __ as the starting index.

0

33
New cards

If you leave out the end index when slicing an expression, Python uses _____________ as the end index.

The length of the list.

34
New cards

Invalid indexes cause slicing expressions to raise an exception. (True or False)

False

35
New cards

If the end index specifies a position beyond the end of the list, an exception will be raised. (True or False)

False

36
New cards

If the start index specifies a position before the beginning of the line, Python will use 0 instead. (True or False)

True

37
New cards

If the start index is greater than the end index, the expression will return a(n) ___________.

empty list

38
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

my_list = numbers[1:3]

print(my_list)

[2, 3]

39
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

my_list = numbers[:1]

print(my_list)

[1]

40
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

my_list = numbers[1:]

print(my_list)

[2, 3, 4, 5]

41
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

my_list = numbers[:]

print(my_list)

[1, 2, 3, 4, 5]

42
New cards

What will the following code display?

numbers = [1, 2, 3, 4, 5]

my_list = numbers[-3:]

print(my_list)

[3, 4, 5]

43
New cards

You can search for an item in a list using the __ operator.

in

44
New cards

What will the following code display?

names = ['Jim', 'Jill', 'John', 'Jasmine']

if 'Jasmine' not in names:

print('Cannot find Jasmine')

else:

print('Jasmines family:')

print(names)

['Jim', 'Jill', 'John', 'Jasmine']

45
New cards

_______ have numerous methods that allow you to work with the elements that they contain. Python also provides some built-in functions that are useful for working with _____.

lists

46
New cards

This list method adds the item passed to its argument to the end of a list.

append

47
New cards

This list method returns the index of the first list element whose value is equal to the item passed to its argument.

index

48
New cards

When using an index method on a list, if the item passed as an argument to the function is not found in the list, a ValueError is raised. (True or False)

True

49
New cards

When using the insert method, if you specify an index beyond the end of the list, the item will be inserted into the _____ of the list.

end

50
New cards

When using the insert method, if you specify a negative number with an invalid index, the item will be inserted into the _____ of the list.

beginning

51
New cards

The ______ method inserts an item into the list at a specified index.

insert

52
New cards

The _____ method sorts the items in a list so they appear in ascending order.

sort

53
New cards

The _______ method removes the first occurrence of an item from the list. If the item is not found, a ValueError is raised.

remove

54
New cards

If you want to remove an item at a specific index in a list, you would use the ___ statement.

del

55
New cards

If you want to return the highest value in a list, you would use the ___ statement.

max

56
New cards

If you want to return the lowest value in a list, you would use the ___ statement.

min

57
New cards

Calling a remove statement in a list removes the element at a specified index. (True or False)

False

58
New cards

Calling a del statement in a list removes the element at a specified index. (True or False)

True

59
New cards

How do you find the lowest value in a list?

min()

60
New cards

How do you find the largest value in a list?

max()

61
New cards

Which of the following statements would you use to add the string 'Wendy' to the list at index 0?

name = []

a. names[0] = 'Wendy'

b. names.append('Wendy')

b

62
New cards

A ____________________ list is a list that has other lists as its elements.

two-dimensional

63
New cards

Two-dimensional lists are also called ________ lists.

nested

64
New cards

A _______ is an immutable sequence, which mean that it's content cannot be changed.

tuple

65
New cards

Tuples are enclosed in ___________.

parentheses

66
New cards

Lists are enclosed in ________.

brackets

67
New cards

Tuples support the same operations as lists, except those that change the content of the list. (True or False)

True

68
New cards

A list is processed faster than a tuples. (True or False)

False

69
New cards

Data in a tuple can be changed. (True or False)

False

70
New cards

Some operations in Python require a tuple. (True or False)

True

71
New cards

What function would you use to convert a tuple to a list?

list()

72
New cards

What function would you use to convert a list to a tuple?

tuple()

73
New cards

What command would you use for matplotlib?

import matplotlib

74
New cards

Each function call when you import matplotlib, must be prefixed by __________?

matplotlib.pyplot

75
New cards

If you want to use the plt prefix to call functions, what statement would you write to import matplotlib?

import matplotlib.pyplot as plt

76
New cards

import matplotlib.pyplot as plt allows you to use which prefix to call functions?

plt

77
New cards

In order to create a line graph in matplotlib, you must create two separate lists for the x and y coordinates. (True or False)

True

78
New cards

To create a graph in matplotlib, we would call the ______function.

plot()

79
New cards

What command would you use to show the graph in matplotlib?

plt.show()

80
New cards

What function would you use to create a title for a graph?

plt.title()

81
New cards

What would you use to remove an element from a specific index?

del()

82
New cards

When working with multiple sets of data, one would typically use a(n)

nested list

83
New cards

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

False

84
New cards

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

False

85
New cards

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

insert()

86
New cards

What method or operator can be used to concatenate lists?

+

87
New cards

What is the first negative index in a list?

-1

88
New cards

What list will be reference by the variable number after the following code is executed?

number = range(0, 9, 2)

[0, 2, 4, 6, 8]

89
New cards

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

False