DEV Community

Shaique Hossain
Shaique Hossain

Posted on

Tuples and Sets in Python

Tuples and sets in python are both data structures for storing collections of items.

  • Tuples: Ordered, immutable sequences of elements. Defined using parentheses ( ), tuples can store items of different types and support indexing. Once created, the elements cannot be changed, making tuples suitable for fixed collections of data.

  • Sets: Unordered collections of unique elements. Defined using curly braces { } or the set() function, sets automatically eliminate duplicates and support operations like union, intersection, and difference. Sets are mutable, meaning elements can be added or removed, but they do not support indexing.

Both are useful for different scenarios in Python programming.

Top comments (0)