What is a Set?
A set is an unordered collection with no duplicate elements
Basic uses include membership testing and eliminating duplicate entries
Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Curly braces or the set() function can be used to create sets
Note:
  • To create an empty set you have to use set(), not {}
  • Set items are unchangeable, but you can remove items and add new items.
  • A set is a collection which is unordered, unchangeable, and unindexed.
  • As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered.
Example:1
        basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
        print(basket) # show that duplicates have been removed
        
Output:
        {'orange', 'banana', 'pear', 'apple'}
        
Example:2
        basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
        'orange' in basket                 # fast membership testing
        
Output:
            True
        
Example:3
        basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
        'crabgrass' in basket                 # fast membership testing
        
Output:
        False
        
Example:4
        # Demonstrate set operations on unique letters from two words
        a = set('abracadabra')
        b = set('alacazam')                   #with single quote
        c = set("abracadabra")                #with double quote                 
        print(a)                              # unique letters in a
        print(c)                              # unique letters in c
        print(a - b)                          # letters in a but not in b
        print(a | b)                          # letters in a or b or both
        print(a & b)                          # letters in both a and b
        print(a ^ b)                          # letters in a or b but not both
        
Output:
        {'a', 'r', 'b', 'c', 'd'}
        {'b', 'r', 'c', 'd', 'a'}
        {'r', 'd', 'b'}
        {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
        {'a', 'c'}
        {'r', 'd', 'b', 'm', 'z', 'l'}
        
Example:5
        #Similarly to list comprehensions, set comprehensions are also supported:
        a = {x for x in 'abracadabra' if x not in 'abc'}
        print(a)
        
        
Output:
        {'r', 'd'}
        
Data Types: Set items can be of any data type.

Example:6
        set1 = {"apple", "banana", "cherry"}
        set2 = {1, 5, 7, 9, 3}
        set3 = {True, False, False}

        print(set1)
        print(set2)
        print(set3)
                
        
Output:
        {'cherry', 'apple', 'banana'}
        {1, 3, 5, 7, 9}
        {False, True}
        
Example:7
A set can contain different data elements in a single set also.
        set1 = {"abc", 34, True, 40, "male"}
        print(set1)
                
        
Output:
        {True, 34, 40, 'male', 'abc'}
        
Example:8
           #We can create a set from a range.
           set(range(10))     
        
Output:
            {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
        
Example:9
           #we can create a set from a list.
           set([0, 1, 2, 3, 0, 1, 2, 3, 4, 5])     
        
Output:
            {0, 1, 2, 3, 4, 5}
        
3 of 3