Function Details: add

Description


Adds an element to the set.


Extended Description


The add() method adds an element to the set if it's not already present. If the element is already in the set, the method does nothing. The element must be hashable (immutable). Sets only store unique elements, so duplicates are automatically eliminated. This method modifies the set in-place and doesn't return a value.


Function Signature


set.add(element: Any) -> None

Module: set

Class: set

Parameters



Parameter List


  • element: Any

Return


This method doesn't return a value (None).


Return Type


None

Output

Explanation

This example shows adding a new element and attempting to add an existing element.