1.2 Python Data Structures, String, Date and Time Flashcards
(64 cards)
A data structure in Python that is ordered and mutable (changeable)
List [ ]
Items in this data structure do not need to be homogenous or of the same type
List
Elements in this data structure are indexed according to a definite sequence and the indexing is done with 0 being the first index
List
A list inside a list is called
Nested list
It can have any number of items and they may be of different types (integer, float, string etc)
List
The index of -1 refers to the last item, -2 to the second last item and so on
Negative indexing
Add an element to the end of the list
append()
Add all elements of a list to the end of another list
extend()
Insert an item at the defined index
insert()
Removes an item from the list
remove()
Removes and returns an element at the given index
pop()
Removes all items from the list
clear()
Returns the index of the first matched item
index()
Returns the count of number of items passed as an argument
count()
Sort items in a list in ascending order
sort()
Reverse the order of items in the list
reverse()
Returns a shallow copy of the list
copy()
This data structure is an unordered collection of items. Every element is unique (no duplicates) and immutable (cannot be changed)
Set { }
Although a set element is immutable, a set itself is _____________. We can add or remove items from it
mutable
A set cannot have mutable elements like lists, sets, or ______________ as its elements
dictionaries
Adds an item to a set
add()
Adds multiple items to a set
update()
To remove an item in a set, use the remove() or _________ method
discard()
If the item to remove does not exist in a set, __________ will raise an error
remove()