Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 15, 2020 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/a7997a46b1757b90e55dd4ce6bbe73cc to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/a7997a46b1757b90e55dd4ce6bbe73cc to your computer and use it in GitHub Desktop.
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