Functions are a way to save time and energy by storing commonly used blocks of code in one named set. For a real-world example, when you’re drinking a glass of water, the entire task might look like this:
- Find glass
- Bring over to water source
- Pour water into glass
- Make sure water doesn’t overflow!
- Drink water
But instead of saying all of that, you could just say you’re drinking water! Functions work the same way. Multiple lines of code can be included in one function that you name and set up to be used in your program.