Which function is use for comparing elements of both tuples.
Answers
Answered by
5
Answer:
cmp() function
This is used to compare two tuples.
Answered by
0
cmp() function is used for comparing elements of both tuples.
Explanation:
The cmp() Python tuple method is used to compares elements of two tuples.
- Syntax - cmp(tuple1, tuple2)
- Parameters - (tuple1) −Denotes the first tuple to be compared
- (tuple2) − Denotes the second tuple to be compared
Return Value - The following logic used to get the result.
- If elements in both the tuple are of a similar type then compare and return the result.
- If elements in both the tuple are of a similar type then it checks to verify is there are numbers.
- In case they are numbers then perform numeric coercion if necessary and compare.
- In case if anyone element is a number, then the other element is "larger" (numbers are "smallest"), else types are sorted alphabetically by name.
- The longer tuple becomes "larger" if we hit the end of one of the tuples. If we exhaust both tuples and share the same results, the result is a tie, which means that 0 is returned.
Similar questions
Computer Science,
5 months ago
Biology,
5 months ago
Math,
5 months ago
Computer Science,
9 months ago
Computer Science,
9 months ago