B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Python Tuple Exercises with Solutions | LiveCodeProgramming

Python Tuple Exercises

Practice these Python tuple exercises to master the concept of immutable sequences.

इन Python tuple exercises को हल करके आप tuples की समझ को मजबूत कर सकते हैं।

1. Create a tuple of numbers and print the sum.
numbers = (10, 20, 30, 40)
print(sum(numbers))
100
2. Count how many times 'apple' appears in the tuple.
fruits = ('apple', 'banana', 'apple', 'orange')
print(fruits.count('apple'))
2
3. Find the index of 'banana' in the tuple.
fruits = ('apple', 'banana', 'cherry')
print(fruits.index('banana'))
1
4. Slice a tuple to get only the last 3 items.
data = (1, 2, 3, 4, 5, 6)
print(data[-3:])
(4, 5, 6)
5. Unpack the following tuple into variables a, b, c.
person = ("Aryan", 18, "India")
a, b, c = person
print(a)
print(b)
print(c)
Aryan
18
India