Q. Consider the following tuples, tuple1 and tuple2:


tuple1 = (23,1,45,67,45,9,55,45)

tuple2 = (100,200)


Find the output of the following statements:


i. print(tuple1.index(45))

ii. print(tuple1.count(45))

iii. print(tuple1 + tuple2)

iv. print(len(tuple2))

v. print(max(tuple1))

vi. print(min(tuple1))

vii. print(sum(tuple2))

viii. print( sorted ( tuple1 ) )

print(tuple1)


Answer :-

i. print(tuple1.index(45))

Output :- 2

Explanation :- It return the index of existing element of tuple.

ii. print(tuple1.count(45))

Output :- 3

Explanation :- It return the count of a member elements in a given sequence.

iii. print(tuple1 + tuple2)

Output :- (23, 1, 45, 67, 45, 9, 55, 45, 100, 200)

Explanation :- It return the new tuple which is joined of tuple1 & tuple2.

iv. print(len(tuple2))

Output :- 2

Explanation :- It return the length of tuple.

v. print(max(tuple1))

Output :- 67

Explanation :- It return the element from the tuple having maximum value.

vi. print(min(tuple1))

Output :- 1

Explanation :- It return the element from the tuple having minimum value.

vii. print(sum(tuple2))

Output :- 300

Explanation :- It return the addition of tuple.

viii.
print( sorted ( tuple1 ) )
print(tuple1)

Output :-
[1, 9, 23, 45, 45, 45, 55, 67]
(23, 1, 45, 67, 45, 9, 55, 45)

Explanation :- It return the sorted list not tuple because tuple is immutable.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post