Previous Lesson | Current Lesson | Next Lesson |
Question 1
l = (23, "dog", 5)
Take the Python object elements, separate them with commas, and surround with parentheses. Python will do the rest of the (hard) work for you.
Question 2
Building on from the previous solution, we have:
t = (23, "dog", 5)
print(t[2])
This will output:
5
Remember, to access the nth
element of a tuple
, we must use n - 1
as the
index. In this case, we want the first element, so we must use the index 3 - 1 = 2
.