CBSE Class 11 Computer Science Question 69 of 88

Tuples and Dictionary — Question 34

Back to all questions
34
Question

Question 17

Consider two tuples t1 & t2 given below:

t1 = (100, 200, 300)
t2 = (10, 20, 30, 40)

Write the output of the following statements:

(a)

t1, t2 = t2, t1  
print(t1)   
print (t2)

(b) print (t1!=t2)

(c) print (t1 < t2)

Answer

(a)

Output
(10, 20, 30, 40)
(100, 200, 300)
Explanation

In the code t1, t2 = t2, t1, Python performs tuple unpacking and assignment simultaneously. This means that t1 is assigned the value of t2, and t2 is assigned the value of t1. As a result, t1 becomes (10, 20, 30, 40) and t2 becomes (100, 200, 300).

(b)

Output
True
Explanation

The code print(t1 != t2) compares the tuples t1 and t2 to check if they are not equal. Since t1 is (100, 200, 300) and t2 is (10, 20, 30, 40), they have different lengths and different elements. Therefore, it evaluates to True.

(c)

Output
False
Explanation

The code print(t1 < t2) compares the tuples t1 and t2 element by element. Since t1 = (100, 200, 300) and t2 = (10, 20, 30, 40), the comparison starts with the first elements, where 100 < 10 is False. Therefore, the tuple t1 is not less than t2, and the code prints False.