Convert String to Set in Python Last Updated : 19 Feb, 2025 Comments Improve Suggest changes Like Article Like Report There are multiple ways of converting a String to a Set in python, here are some of the methods.Using set()The easiest way of converting a string to a set is by using the set() function.Example 1 : Python s = "Geeks" print(type(s)) print(s) # Convert String to Set set_s = set(s) print(type(set_s)) print(set_s) Output<class 'str'> Geeks <class 'set'> {'s', 'e', 'k', 'G'} Let's explore other methods of converting string to set:Table of ContentUsing set() with split() method (for words)Using dict.fromkeys()Using set() with split() method (for words)To convert words from a sentence into a set, use spilt() method before set().Example: Python s = "Geek for Geeks" # split the string and then convert it to set set_words = set(s.split()) print(set_words) Output{'for', 'Geeks', 'Geek'} Using dict.fromkeys()We can also convert a string to a set by using dict.fromkeys() as it creates a dictionary from an iterable and sets the values to none for every key.Example: Python # create a string s = "developer" set_s = set(dict.fromkeys(s)) print(set_s) Output{'l', 'v', 'o', 'd', 'e', 'p', 'r'} Comment More infoAdvertise with us Next Article Convert String to Set in Python M mukulsomukesh Follow Improve Article Tags : Python python-set python-string Practice Tags : pythonpython-set Similar Reads Convert Set to String in Python Converting a set to a string in Python means changing a group of unique items into a text format that can be easily read and used. Since sets do not have a fixed order, the output may look different each time. For example, a set {1, 2, 3} can be turned into the string "{1, 2, 3}" or into "{3, 1, 2}" 2 min read Convert Object to String in Python Python provides built-in type conversion functions to easily transform one data type into another. This article explores the process of converting objects into strings which is a basic aspect of Python programming.Since every element in Python is an object, we can use the built-in str() and repr() m 2 min read set() Constructor in Python In Python, the set() constructor is used to create a set object. A set is a built-in data type that stores an unordered collection of unique elements. The set() constructor can be used to create an empty set or convert other data types (like lists, tuples, or strings) into a set.Example:Python# Exam 2 min read Convert Tuple to List in Python In Python, tuples and lists are commonly used data structures, but they have different properties:Tuples are immutable: their elements cannot be changed after creation.Lists are mutable: they support adding, removing, or changing elements.Sometimes, you may need to convert a tuple to a list for furt 2 min read Python | Set 3 (Strings, Lists, Tuples, Iterations) In the previous article, we read about the basics of Python. Now, we continue with some more python concepts. Strings in Python: A string is a sequence of characters that can be a combination of letters, numbers, and special characters. It can be declared in python by using single quotes, double quo 3 min read Like