In this Python set program, we will create a set in Python and add some elements in it as an example 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.
Create a set in Python:
Steps to solve the program
- Create a set using {}.
- Add some elements to the set.
- Print the set.
a = {1,2,3,5,6}
print("Set: ",a)
Output :
Set: {1, 2, 3, 5, 6}
add an element to a set.