VOOZH about

URL: https://www.geeksforgeeks.org/python/convert-string-to-set-in-python/

⇱ Convert String to Set in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert String to Set in Python

Last Updated : 15 Jul, 2025

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 : 


Output
<class 'str'>
Geeks
<class 'set'>
{'s', 'e', 'k', 'G'}

Let's explore other methods of converting string to set:

Using set() with split() method (for words)

To convert words from a sentence into a set, use spilt() method before set().

Example:


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:


Output
{'l', 'v', 'o', 'd', 'e', 'p', 'r'}
Comment
Article Tags: