-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
If we go back to our containers analogy, we have different types of containers. For example, in the kitchen, there are containers that we use to store leftovers. We have certain expectations for the content of these containers, for example, that we should be able to reheat it.
And in the kitchen, we also have some containers that are great for liquids (yes, I believe they call these bottles); for these, we have other expectations, such as that we can serve it in a glass.
Okay, back to code.
Let’s say we have two variables:
number = 42
name = "Zia"
What you can’t just see from this code is that these are actually stored in different types of containers. And because of that, there are different things you can do with these types of variables. For example, I can do mathematical operations with the number variable, but I cannot subtract 7 from the name variable.
And that’s why all variables have a type...