Python Practice › Set Programs › Program 32
Add several elements
Write a Python program to add several elements at once.
Input
{1, 2}, add [3, 4, 2]Output
{1, 2, 3, 4}Approach
update()takes any iterable.
Solution
s = {1, 2}s.update([3, 4, 2])print(s)Output
{1, 2, 3, 4}Learn the concept
New to this topic? Read the lesson, then come back.