Python Set

Set is a mutable and unique collection in Python. It can contain only immutable objects like numbers, strings and tuple.

Example:

    >>> s = {1, 2.3, "apple", 3, 4}
    >>> type(s)
    set
                                

Python Set Properties

  • Set is a unique collection like dictionary keys.
  • Set does not has sequential indexes.
  • Set is mutable like list and dictionary.
  • Set can consist of only immutable objects like dictionary keys.

Single Value Tuple Representation

    >>> s = {}
    >>> type(s)
    dict
    >>> s = set()   # empty set
    >>> type(s)
    set
                                

Python Set Attributes

Set has many built-in functions, as listed below:

    add
    clear
    copy
    difference
    difference_update
    discard
    intersection
    intersection_update
    isdisjoint
    issubset
    issuperset
    pop
    remove
    symmetric_difference
    symmetric_difference_update
    union
    update