From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Functions

Functions

- A function can be thought of as a machine. Like this toaster. We put in bread. And we get out toast. It applies the toasting function to the bread. What if I put in these breakfast pastries? Well, it's not bread, but a toaster can still apply the toasting function to it. Look, it returns toasted breakfast pastries. What if I put in this brick? Or three bricks? This gallon of milk? Hmm, if only this toaster were better programmed to accommodate these inputs. Let's go to the code. We've seen a few functions so far. So print hello world, first one we saw. And print is a function. It has a function name, print. It has these parentheses where you can stick all of your inputs or arguments. This is like bread going into the toaster and the argument for here is hello world. And in Python we can even define our own functions. It's a bit like defining variables. The function name rules are the same as the rules for…

Contents