Set in Python
Last updated Aug 09, 2021Set
The data type which is used to store multiple items in a single variable is known as sets. It is a data type that is used to store data. It is a collection that is both unordered and unindexed. Set is also denoted within Curly brackets{}.
Now we will understand about sets with the help of an example:-
s = set([1, 2, 3, 4, 5]) print(s) |
{1, 2, 3, 4, 5} |
So you can see that we had created a set first and then we had added a certain data which is printed within curly brackets as our final output.
Let's take another example of sets in python:-
set1 = {1, 2, 3, 4, 3, 2} print(set1) |
{1, 2, 3, 4} |
So we had got the output but the numbers in output have been reduced as in sets we get a value only once so we got the values for a single time and we hope that you understand this topic well.
Article Contributed By :
|
|
|
|
69 Views |