In python documentation list is defined as:
mutable sequences, typically used to store collections of homogeneous items (where the precise degree of similarity will vary by application).
Why it's used to store collections of homogeneous items?
Are a string and an int item also homogeneous then?
a = [12,"hello"]
Homogeneous means "of the same or a similar kind or nature".
While any value can be stored in a list along with any other value, in doing so the definition of "kind or nature" must be widened when dealing with the sequence. During this widening (or "unification"), the set of operations that can be performed upon every item in the sequence becomes the "lowest common set of operations" shared between all items.
This is why "[list are] typically used to store collections of homogeneous items" - so the items in the sequence can be treated with an appropriate level of unification:
# a list of animals that can "speak"
animals = [Dog(), Cat(), Turkey()]
for a in animals:
a.speak()
# .. but a string cannot "speak"
animals = [Dog(), "Meow!", Turkey()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With