When it is required to test if a tuple has distinct elements in it, the 'set' method and the 'len' method can be used.
Python comes with a datatype known as 'set'. This 'set' contains elements that are unique only.
The 'len' method gives the length of the parameter passed to it.
Below is a demonstration of the same −
my_tuple_1 = (11, 14, 54, 0, 58, 41) print("The tuple is : ") print(my_tuple_1) my_result = len(set(my_tuple_1)) == len(my_tuple_1) print("Is the tuple distinct ? ") print(my_result)
The tuple is : (11, 14, 54, 0, 58, 41) Is the tuple distinct ? True