Member-only story
Complete Free Course on Python and Data Engineering
3 min readAug 3, 2024
There are four complex types in Python: Lists, Tuples, Sets and Dictionaries, let’s start talking about each one of them separately and giving practical examples.
Lists:
- Lists are mutable elements.
- Can have items of different types, strings, characters, integers, and floats all in the same list.
- Its index starts with zero.
- They are ordered and have duplicated elements. Its operations, append, remove and modify.
The code below is a practical example:
Tuples:
- Immutable data.
- Can be used as immutable lists.
tuple = (1, 2, 3, 4, 5, "b", "c", "d")
- Can be used as a collection of fields, the number of elements is fixed, and the order is important.
city, year, pop, chg, area = ('Tokyo', 2003, 32_450, 0.66, 8014)
The code below is a practical example:
Sets:
- Mutable data.
- Elements are not ordered, nor duplicated.
- Sets are hashable so…