Chapter 5 - Lists and Tuples Flashcards
1
Q
What is a list?
A
A list in python is a type of sequence, like a string
2
Q
Examples of operations on lists?
A
- isEmpty() = Test for empty list
- append(item) = add a new item to list to the end of the list
- remove(item) = remove the first occurrence of an item from list
-len() = return the number of items
-index(item) = return the position of item - insert( pos, item) = insert a new item at position pos
- pop() = remove and return the last item in the list
- pop(pos) = remove and return the item at postition pos
3
Q
is len() a function or method
A
function
4
Q
What are tuples?
A
similar to lists but they are immutable, which means that once defined, they cannot be changed.