2. Problem to add elements to set in python

In this Python set program, we will add elements to set in Python and print the set to see the result 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.

Add elements to set:

Steps to solve the program
  1. Create a set using {}.
  2. Add some elements in the set.
  3. Add an element in the set using add() function.
  4. Print the output.
				
					a = {1,2,3,5,6}
print("Original set: ",a)
a.add(7)
print("New set: ",a)
				
			

Output :

				
					Original set:  {1, 2, 3, 5, 6}
New set:  {1, 2, 3, 5, 6, 7}
				
			

create a set with some elements.

remove an element from a set.

Leave a Comment