33. Problem to add multiple element to set

In this Python set program, we will add multiple element to set 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 multiple element to set:

Steps to solve the program

1. Create two sets using {}.
2. Add some elements in the set.
3. Use a for loop to iterate over the second set.
4. During each iteration add the element to the first set using add() function.
5. Print the new set.

				
					a = {1,2,4,5}
print("Original set: ",a)
b = {7,8,9}
for ele in b:
    a.add(ele)
print("New set: ",a)
				
			

Output :

				
					Original set:  {1, 2, 4, 5}
New set:  {1, 2, 4, 5, 7, 8, 9}
				
			

Related Articles

remove a specific element from a set.

remove multiple elements from a set.

Leave a Comment