Page 48 -
P. 48
mixed type
What?!? There’s no way you can mix
data of different types in lists, is
there? Surely this is madness?
No, not madness, just the way Python works.
Python lists can contain data of mixed type. It’s perfectly OK
to mix strings with numbers within the same Python list. In fact,
you can mix more than just strings and numbers; you can store
data of any type in a single list, if you like.
Recall that a Python list is a high-level collection, designed from
the get-go to store a collection of “related things.” What type
those things have is of little interest to the list, because the list
exists merely to provide the mechanism to store data in list form.
So, if you really need to store data of mixed type in a list,
Python won’t stop you.
12 Chapter 1