Functions
Before doing more with our data types, let's explain one other thing we've glossed over. What was that type()
syntax that we used earlier, with the parentheses and everything?
type
is a function. There are a few different useful ways to think about functions in Python:
- A way of doing something in Python. An action. A verb.
- A way of saving some code for use later. Also sometimes called a "routine."
- A way of taking something, doing something with it, and returning some result. This is similar to how functions work in math.
If functions are verbs, then whatever goes in the parentheses are the direct objects. Whatever is placed in the parentheses is given over to the function to perform its action or produce its result. In programming, we call these "parameters" or "arguments," as in, the type()
function takes one argument.
In the case of type()
, the function takes an argument, looks at it, and returns a representation of the data type of the argument.