Skip to content
Exercise · Q1

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)

Rajasthan RbseTextbookSubjective· 3mImportance★★★★★est
43% · 13/30 Questions
✓ Free question

Tuple methods and built-ins on tuple1 = (23,1,45,67,45,9,55,45) and tuple2 = (100,200) — key facts: index() reports the FIRST occurrence, + concatenates into a new tuple, and sorted() returns a list while leaving the tuple untouched (tuples are immutable).

Index the elements of tuple1 first: 23(0), 1(1), 45(2), 67(3), 45(4), 9(5), 55(6), 45(7). Now each statement:

#StatementHow it evaluatesOutput
iprint(tuple1.index(45))position of the FIRST 45 — it sits at index 2 (later 45s at 4 and 7 are ignored)2
iiprint(tuple1.count(45))45 appears at indices 2, 4 and 73
iiiprint(tuple1 + tuple2)concatenation builds a NEW 10-element tuple (neither operand changes)(23, 1, 45, 67, 45, 9, 55, 45, 100, 200)
ivprint(len(tuple2))tuple2 has two elements2
vprint(max(tuple1))largest element67
viprint(min(tuple1))smallest element1
viiprint(sum(tuple2))100 + 200300
viiiprint(sorted(tuple1)) then print(tuple1)sorted() returns a new sorted list — it cannot and does not modify the immutable tuple, so the second print shows tuple1 exactly as created[1, 9, 23, 45, 45, 45, 55, 67] and (23, 1, 45, 67, 45, 9, 55, 45)

Complete run:

2
3
(23, 1, 45, 67, 45, 9, 55, 45, 100, 200)
2
67
1
300
[1, 9, 23, 45, 45, 45, 55, 67]
(23, 1, 45, 67, 45, 9, 55, 45)
Watch out

Part (viii) is the trap: sorted(tuple1) prints with square brackets (it returns a list, since a tuple cannot be sorted in place), and the follow-up print(tuple1) proves the original tuple is unchanged. Writing (1, 9, 23, …) with round brackets for the first line loses the mark.

✓Final answer

i) 2 · ii) 3 · iii) (23, 1, 45, 67, 45, 9, 55, 45, 100, 200) · iv) 2 · v) 67 · vi) 1 · vii) 300 · viii) sorted() prints the list [1, 9, 23, 45, 45, 45, 55, 67] and tuple1 remains (23, 1, 45, 67, 45, 9, 55, 45).

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.