Convert String to Set in Python Last Updated : 15 Jul, 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 Python | Set 3 (Strings, Lists, Tuples, Iterations) 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 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 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 set copy() in python The copy() method returns a shallow copy of the set in python. If we use "=" to copy a set to another set, when we modify in the copied set, the changes are also reflected in the original set. So we have to create a shallow copy of the set such that when we modify something in the copied set, change 2 min read set() Function in python set() function in Python is used to create a set, which is an unordered collection of unique elements. Sets are mutable, meaning elements can be added or removed after creation. However, all elements inside a set must be immutable, such as numbers, strings or tuples. The set() function can take an i 3 min read set() Function in python set() function in Python is used to create a set, which is an unordered collection of unique elements. Sets are mutable, meaning elements can be added or removed after creation. However, all elements inside a set must be immutable, such as numbers, strings or tuples. The set() function can take an i 3 min read Like