-
-
Save IndhumathyChelliah/a7997a46b1757b90e55dd4ce6bbe73cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1={1,2,3,4,5} | |
print (s1)#Output: {1, 2, 3, 4, 5} | |
s2={'red','blue','orange'} | |
print (s2)#Output:{'red', 'orange', 'blue'} | |
#set can contain different datatypesS.ets are unordered, so it will print in any order. | |
s3={1,'car',2,'bus'} | |
print (s3)#Output: {'car', 1, 2, 'bus'} | |
# set can't have mutable elements like list | |
s4={1,2,3,[4,5]} | |
print (s4) #Output: TypeError: unhashable type: 'list' | |
# we can create set by using set() - set constructor | |
s5=set([1,2,3]) | |
print (s5)#Output: {1, 2, 3} | |
# set has no duplicates. | |
s6={1,2,3,1,2,3,1,2,3} | |
print (s6)# Output: {1, 2, 3} | |
#we can't create empty set using {}. To create empty set we use set() | |
s7=set() | |
print (s7) #Output: set() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment