Python Set - add method

To add an element to a Python Set Object invoke the add( ) method that is exposed on the Python set object

Set Updated 16 Sep 2016 1 min read

Method signature

add(element_in)

Parameters

element_in : The element that is be added to the Python set object.

Method Overview

The add() method adds an element to an existing Python set object.

Example

python
# Example Python program that adds elements to an exisiting set

            seafoodMenu = {"Salmon","White Fish","Oysters"}

# Add more elements

            seafoodMenu.add("Shrimp")

            seafoodMenu.add("Lobster")

# Print the set updated with new elements

            print("New set after adding elements:")

            print(seafoodMenu)