Tuples Flashcards

1
Q

What is a tuple?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is the ‘zip()’ function used?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to work with a list of tuples?

A

To work with a list of tuples use the double bracket syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly