DEV Community

Tommi k Vincent
Tommi k Vincent

Posted on

Adding Items to a Set in Python.

we add elements to a set using the add() method. Again as discussed there is no specific index attached to the newly added element.

by using our previous data let's add another element in the existing set.

players = set(['Madueke','Reece James','Cole Palmer','Raheem Sterling','Levi Colwil','Thiago Silva',
'Mudryk','cucurella','Nkunku Christopher'])


players.add("Enzo Fernandez")

print(players)
Enter fullscreen mode Exit fullscreen mode

output:
When the above code is executed, it produces the following result

'Mudryk', 'Levi Colwil', 'Thiago Silva', 'Nkunku Christopher', 'Raheem Sterling', 'Reece James', 'Madueke', 'Enzo Fernandez', 'cucurella', 'Cole Palmer'}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)