Write a Python program to Convert Set to String


This program creates a set s with the letters in the word "TutorJoes". The set s is then printed to the console along with its data type, which is set. Next, the set s is converted to a string using the str() function. The resulting string is then stored in a variable new and printed to the console along with its data type, which is str.

Source Code

# create a string str
s = {'T', 'u', 't', 'o', 'r', 'J', 'o', 'e' , 's'}
print("String  Value : " ,s)
print("Type of string : " ,type(s))
 
# convert Set to String
new = str(s)
print("\nSet Convert to String : ", new)
print("Type of String : ",type(new))
 

Output

String  Value :  {'T', 's', 't', 'o', 'u', 'J', 'e', 'r'}
Type of string : <class 'set'>

Set Convert to String :  {'T', 's', 't', 'o', 'u', 'J', 'e', 'r'}
Type of String :  <class 'str'>