Instruction
It's time to wrap things up! First, let's have a quick review of what we've learned:
-
Tuples may or may not be defined with parentheses, but they require commas:
sample_tuple = 1, 2, 3 another_tuple = (1, 2, 3)
-
To access an element or a few of them, use square brackets:
sample_tuple[1] sample_tuple[:2]
-
To iterate over a tuple, use a
forloop:for item in sample_tuple:
-
To check if a tuple contains an element, use the
inoperator:if item in sample_tuple:
-
You can unpack a tuple into a group of variables:
number_one, number_two, number_three = sample_tuple
-
You can return tuples from functions and precede a function parameter with an asterisk (
*) if you want to allow a varying number of arguments:def function_name(*args):
All right, how about a short quiz now?
Exercise
Click to continue.



