PY LISTS Flashcards
What is the purpose of Lists?
to store multiple items in a single variable
What ate the 3 in built data types to store data and info
tuple, set, dictinary
What are the characteristics of the List items
changeable, duplicate, indexed/ ordered
- indexed implies they have fixed order and any new item is added to the end of the list
- dupilcate values are allowed because lits are indexed
- changeable: we can delete, edit, add things to the list after it has been created
_____ is the index number of the 1st list item
0
_____ is another way of producing a list using doble round brackets
list constructor
How can we access specific list items?
index numbers
how can we obtain the last item or the ones preceding it in a list?
print(list[len(list)-1])
OR
We can do negative indexing
[:6] when such a command has been produced what kind of output should we expect?
the output will start from 1st item and exclude the end value
what output to expect with this command[2:]
the output will include the index item 2 and go on till the end
____ keyword is used to determine if a specified item is present in the list
in
how can we change.a specific item in the list
mylist[2] = “kd”
so the output will replace that index item with the new one
how to change multiple items in the list?
using a range of index when producing the command for new words
list{2:4} = new items
when will the length of the list change?
When number of items inserted does not match the no. of items replaced and the items will get adjusted accordingly
if i replace more items than i insert, what will happen
eg;
mylist=[pen, pencil,pin,kit,kat]
mylist[2:4]=[book}
then items in the range index will change rest will get adjusted to it i.e. items in the position of 2 and 3 index values will get replaced by the sing;e item book
____ fxn increases the list items without changing the items
mylist.insert(index number, “item”)
it increased the items in the list