Set add() Syntax
Syntax: set.add( elem )
Parameters
- elem: The element that needs to be added to a set.
Return
The add() method does not return anything
Set add() Method in Python
The Python set add() method adds a given element to a set if the element is not present in the set in Python.
Example: Add Element to an Empty set
It is used to add a new element to the empty set.
Python3
GEEK = set () GEEK.add( 's' ) print ( "Letters are:" , GEEK) # adding 'e' again GEEK.add( 'e' ) print ( "Letters are:" , GEEK) # adding 's' again GEEK.add( 's' ) print ( "Letters are:" , GEEK) |
Output
Letters are: {'s'}
Letters are: {'e', 's'}
Letters are: {'e', 's'}
Contact Us