![]() ![]() |
Conceptual Review (page 31 of 55) |
The items in a list do not all have to have the same data type. Notice the different data types in the following stuff list.
stuff = ['house', 23, 23.8, 'clothes', [4, 7], [4, 'bill']]
We may add items to a list using append or insert. append() adds items to the end of the list. insert() adds items to a specific position.
stuff.append(12) # Append the 12 to the end of the list
evens.insert(0, 1) # Insert the number 1 in the 0th index position.
We may also remove items using pop() or remove().
evens.pop(3) # Remove the item contained in the 3rd indexed position
evens.remove(12) # Clear a specific item (not an indexed position)
We may also clear all of the items in a list using clear()
evens.clear()