DEV Community

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

Posted on

Sets in Python.

A Set in Python programming is an unordered collection data type that is iterable, mutable and has no duplicate elements.
**
Key Concepts in Sets**
1 Elements in the set cannot be duplicates.
2 Elements in sets are immutable.
3 There is no index attached to any element in the Python set.
when creating a set we use a set() function or place all elements within a pair of curly brackets.

**
example of set in python**

clubs = set(['Chelsea','Manchester-United','Man-city','Liverpool','Totehnam','NewCastle'])
captains  = {"Reece James","Bruno Fernandes","Kevin-Debruyne","Vigil",'Son','Trippier'}

position  = {10,8,2,3,1,5}

print(clubs)
print(captains)
print(position)
Enter fullscreen mode Exit fullscreen mode

output
When the above code is executed, it produces the following result. Please note how the order of the elements has changed in the result.

{'Chelsea', 'Manchester-United', 'Totehnam', 'Man-city', 'Liverpool', 'NewCastle'}
{'Vigil', 'Trippier', 'Son', 'Kevin-Debruyne', 'Reece James', 'Bruno Fernandes'}
{1, 2, 3, 5, 8, 10}
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

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