Python Practice › Set Programs › Program 32

Add several elements

EasySet Programs · 32 of 48

Write a Python program to add several elements at once.

Advertisement
Input
{1, 2}, add [3, 4, 2]
Output
{1, 2, 3, 4}

Approach

  1. update() takes any iterable.

Solution

Python
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.

More set programs

← All 48 Set Programs

Leave a Comment