Computer Science
Consider two tuples given below:
tup1 = (1, 2, 4, 3)
tup2 = (1, 2, 3, 4)
What will the following statement print: print (tup1 < tup2)
- True
- False
- Error
- None of these
Python Tuples
3 Likes
Answer
False
Reason — In tuple, the comparison operator starts by comparing the first element from each sequence. If they are equal, it goes on to the next element, and so on, until it finds elements that differ. Since tup1 is (1, 2, 4, 3) and tup2 is (1, 2, 3, 4), the third element of tup1 (which is 4) is greater than the third element of tup2 (which is 3). Hence, tup1 is not less than tup2, so the comparison evaluates to False.
Answered By
2 Likes
Related Questions
Which of the statement(s) is/are correct?
- Python Dictionary is an unordered collection of items.
- Python Dictionary is a mapping of unique keys to values.
- Dictionary is mutable.
- All of these
If tup = (20, 30, 40, 50), which of the following is incorrect?
- print (tup[3])
- tup[2] = 56
- print (max(tup))
- print (len(tup))
Which function returns the number of elements in the tuple?
- len()
- max()
- min()
- count()
To create an empty dictionary, we use the statement as:
- d1 = {}
- d1 = []
- d1 = ()
- d1 == {}