Tuples Flashcards
What is a tuple?
A tuple is a data structure similar to a list but whos data is immutable.
To create a tuple use the rounded brackets.
To create a single item tuple you must use a trailing comma:
my_tuple =(4,)
You can also unpack a tuple by using multiple variables
name, age, occupation = (“murphy”, 39, “Data Engineer”)
How is the ‘zip()’ function used?
The ‘zip()’ function is used to combine two or more iterables (such as lists, tuples, or strings) into a list of tuples paired based on their position.
Note that the zip() function will create an iterator you will need a loop to access the items.
How to work with a list of tuples?
To work with a list of tuples use the double bracket syntax.