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)
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}
Top comments (0)