Lists Flashcards

1
Q

how do you make a list?

A

[]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is list .pop used for?

A

List pop in Python is a pre-defined, in-built function that removes an item at the specified index from the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the index value of each item in a list?

A

Assigned an index value starting at 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what would the code be for retrieving a specific item?

A

print(list_name[2])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you add items to a list

A

.append

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you delete the 5th item in a list?

A

list_name.pop(5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the phrase “lists are mutable” mean

A

elements within the list can be changed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Do list elements all have to be of the same type?

A

NO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If there are 4 items in a list and you wrote print(list_name[5]) what would the result be

A

index error as it is out of range

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you insert an item in a list?

A

list_name.insert(2(place where the item will go), “item to insert”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how would you add 2 lists together?

A

new_list= list_1 + list_2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you multiply a list and what will happen

A

new_list= list_1*3

If, for example, the list included how much ingredients we need for a recipe - and you want to cook 3 * the amount it has listed it will then list the ingredients 3 more times in the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you update a list to contain the contents of another list ?

A

list_name.extent(list_2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you call only a certain range of contents in a list (slice)?

A

You can slice a list by asking calling between 2 index numbers in the list

print(list_name[3:7])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly