Python Flashcards
(6 cards)
What is the difference between a tuple and a list?
A list is an ordered, mutable collection of elements you can add, remove or change elements after the list is created. e.g. l = [1,2,3]
A tuple is an ordered but IMMUTABLE collection of elements. Once a tuple is created, its contents can’t be changed. e.g. t = (1,2,3) They are thus slightly more memory efficient. They are used for fixed data like coordinates or config values.
What is different about sets compared to tuples and lists?
Sets contain UNORDERED and only UNIQUE values e.g. {1,2,3}.
Which brackets are used for sets, lists and tuples?
Sets = {}
lists = []
tuples = ()
Out of sets, tuples and lists, which have only unique values? What is an implication of only having unique values?
Sets. They can’t be accessed with an index.
Out of sets, tuples and lists, which have ordered values?
tuples and lists
Out of sets, tuples and lists, which are mutable?
Sets and lists. Tuples are used for fixed values like coordinates.