Free cookie consent management tool by TermsFeed Python Set - add method | Pythontic.com

Python Set - add method

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:

# 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)


Copyright 2025 © pythontic.com