In this Python set program, we will check whether an element in a set is a substring of a string or not with the help of the below-given steps.
What is set?
Sets are used to store multiple items in a single variable.
The set is one of 4 built-in data types in Python used to store collections of data.
It is an unordered collection data type that is iterable, mutable and has no duplicate elements.
Element in a set is a substring of a string:
Steps to solve the program
1. Create a string and a set containing words.
2. Create a count variable and assign its value equal to 0.
3. Use a for loop to iterate over words in the set.
4. Use an if statement to check whether the word is in string or not.
5. If yes then add 1 to the count variable.
6. If the value of the count variable is greater than 0 then an element in a set is a substring of a string, else not.
7. Print the respective output.
Output :
Related Articles
Python program to check if any element in a set is a prefix of a given string.
Python program to check if any element in a set is a suffix of a given string.
Python program to find the index of an element in a set.
Python program to convert a set to a dictionary with each element as key and value to an empty set.
Python program to create a set of even numbers from 1 to 20.
Python program to create a set of odd numbers from 1 to 20.
find the intersection between multiple sets.