Write a Python program to Convert Tuple to Set


The code is converting a tuple val into a set. The val tuple contains the values 'T', 'u', 't', 'o', 'r', 'J', 'o', 'e' , 's'. First, the tuple val is printed along with its type, which is tuple. Next, the code converts the tuple val into a set and assigns the result to the variable s. The converted set is then printed along with its type, which is set.

Source Code

val = ('T', 'u', 't', 'o', 'r', 'J', 'o', 'e' , 's')
print(val)
print(type(val))
 
print("\nConvert Tuple to Set\n")
s = set(val)
print(s)
print(type(s))

Output

('T', 'u', 't', 'o', 'r', 'J', 'o', 'e', 's')
<class 'tuple'>

Convert Tuple to Set

{'J', 'o', 'u', 's', 'e', 'r', 'T', 't'}
<class 'set'>