Python tuple program to test whether a tuple is distinct or not

In this python tuple program, we will test whether a tuple is distinct or not.

Steps to solve the program
  1. Take a tuple as input.
  2. Create a set of input tuple it will remove the duplicate elements.
  3. Now check whether the length of the tuple is equal to the length of the new tuple i.e. length of set of tuple using an if-else statement.
  4. If they are equal then the tuple is distinct else the tuple is not distinct.
  5. Print the output.
				
					tup = (1,2,3,4)
if len(set(tup)) == len(tup):
    print("Tuple is distinct")
else:
    print("Tuple is not distinct")
				
			

Output :

				
					Tuple is distinct
				
			
				
					tup1 = (3,4,5,4,6,3)
if len(set(tup1)) == len(tup1):
    print("Tuple is distinct")
else:
    print("Tuple is not distinct")
				
			

Output :

				
					Tuple is not distinct
				
			

find values of tuples at ith index number.

convert a tuple to string datatype.

Leave a Comment