Python Set add() Method Tutorial

In this section, we will learn what the Set add() method is and how to use it in Python.

What is Set add() Method in Python?

The Python Set add() method is used to add a new element to a Set object.

Note that if the target Set object had the new element, no action will take place.

Also, the new values will be added to the end of the target Set object.

Python Set add() Method Syntax:

set.add(value)

Set add() Method Parameter:

The method takes one argument and that is the new value we want to add to the target Set object.

Set add() method Return Value

The method does not return a value.

Example: adding elements to python Set

set1 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

set1.add(1000)

set1.add(2000)

set1.add(3000)

print(set1)

Output:

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1000, 2000, 3000}
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies