Lists Flashcards
how do you make a list?
[]
What is list .pop used for?
List pop in Python is a pre-defined, in-built function that removes an item at the specified index from the list.
what is the index value of each item in a list?
Assigned an index value starting at 0
what would the code be for retrieving a specific item?
print(list_name[2])
How do you add items to a list
.append
How would you delete the 5th item in a list?
list_name.pop(5)
What does the phrase “lists are mutable” mean
elements within the list can be changed
Do list elements all have to be of the same type?
NO
If there are 4 items in a list and you wrote print(list_name[5]) what would the result be
index error as it is out of range
How do you insert an item in a list?
list_name.insert(2(place where the item will go), “item to insert”)
how would you add 2 lists together?
new_list= list_1 + list_2
How would you multiply a list and what will happen
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 would you update a list to contain the contents of another list ?
list_name.extent(list_2)
How would you call only a certain range of contents in a list (slice)?
You can slice a list by asking calling between 2 index numbers in the list
print(list_name[3:7])