Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jun 15, 2020
Embed
What would you like to do?
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