DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more