Set in Python – Quickstart

Read following articles to learn more about variables, core datatypes and scope of variables in Python.

Set in Python

  • Set is an unordered collection datatype. Unlike List and Tuple, elements in Set are not stored based on their index positions.
  • Sets can store heterogeneous elements i.e sets can store elements of different datatypes including the collection elements except List. Set does not allow storing List as an element.
  • Set is iterable collection. We can iterate through the elements in Set. But, there is no order defined for elements in Set. During iteration elements can come in any order.
  • Set is mutable collection datatype. It means we can perform add (append), update (change), delete (remove) operations on the set objects.
  • Set does not allow duplicate elements. Sets will always store unique elements. But we can store different case-sensitive elements in it. Elimination of duplicate elements from a collection is the primary use case of Set.
  • Set in Python support mathematical operations like union, intersection, difference, and symmetric difference, subset and super-set.

We have covered each operation that we can perform on Sets in Python.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *