Python Tuple Exercises

Let’s check out some exercises that will help understand tuples better.

Exercise 7-a

Assign the first element of the tuple to answer_1 on line 2


Correct syntax to call a tuple’s element is brackets with the index number inside next to the tuple’s name: 


Index starts with zero.

answer_1 = tt[0]

Exercise 7-b

This time print the third element of the tuple.

0,1,2 … Third element is index 2: [2]

answer_1 = tt[2]

Exercise 7-c

Print the second from the last element of the tuple.

Second from last element has index of -2.

answer_1 = lst[-2]

Exercise 7-d

What's the index of 2?

.index() takes 1 parameter which is the element you’re looking for. Just type it inside .index() and print it to see the value.


Exercise 7-e

How many times does 777 occur?

.count() method tells how many times a value occur in a tuple. You need to type the value you’re checking inside .count()


Exercise 7-f

What is the sum of all the numbers in the tuple?

sum() function will calculate the total sum inside the numbers of your tuple.

ans_1 = sum(tt)

Exercise 7-g

What is the minimum value in the tuple?

min() function will show the minimum value of the tuple.

ans_1 = min(tt)

Exercise 7-h

What is the maximum value in the tuple?

max() function will show the minimum value of the tuple.

ans_1 = max(tt)