How to Convert a Set to a String in Python

0 min read 72 words

If you need to convert a set to a string in Python, then you can do one of the following:

Option 1 – Using map() and join()

str_new = ', '.join(list(map(str, se)))

You can confirm this worked as follows:

print(str_new)
print(type(str_new))

# '1, 2, 3'
# <class 'str'>

Option 2 – Using repr()

r_str = repr(se)

You can confirm this worked as follows:

print(r_str)
print(type(r_str))

# {1, 2, 3}
# <class 'str'>
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags