This page topics close

Python also includes a data type for sets. 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 {}; the latter creates an empty dictionary.

  • Properties of set

    • Order of elements are not preserve.

    • duplicate elements are not allowed.

    #creating set
    print("length of my_set is ",len(my_set))
    {1, 2, 3, 4, 5}
    length of my_set is  5

What next?

The next topic is Python Dictionaries

Share this page