python new set code example
Example 1: empty set python
# Distinguish set and dictionary while creating empty set
# initialize a with {}
a = {}
# check data type of a
print(type(a))
# initialize a with set()
a = set()
# check data type of a
print(type(a))
Example 2: get length of set python
# Create a set
seta = {5,10,3,15,2,20}
# Or
setb = set([5, 10, 3, 15, 2, 20])
# Find the length use len()
print(len(setb))
Example 3: python set
set_example = {1, 2, 3, 4, 5, 5, 5}
print(set_example)
# OUTPUT
# {1, 2, 3, 4, 5} ----- Does not print repetitions