Python Functions
Nov 21, 2023
DataSciencePursuit
Functions are one the most used and also the more challenging concepts, which is why we are starting it early. This section will provide an overview of functions. We will learn details in later sections.
What are functions?
Functions are reusable chunks of code that perform a particular/defined task.
They are most useful when you need to repeat tasks. In this course, we will learn how to create and use functions. The process of creating a function in Python is called function definition and using a function is referred to as calling a function.
For math people, these are very similar to functions in math. For everyone else, before we start seeing code, let us go to the kitchen.
To the kitchen!
When washing dishes, we generally do the following steps, remove as much food as we can, and get some water and soap. Then one by one, scrub the dishes clean, rinse them with non-soapy water and then leave them on the drying rack to dry or dry them with a dish towel. And then repeat the whole process the next time the dishes need to be done.
We can do all this, or we can use the magical invention called a dishwasher. All we have to do is put the dishes and the soap in, close it up, and press a button. It does all the other steps, and a couple of hours later we'll have clean dishes and quite a bit of time saved.
This is similar to how functions work and how helpful they can be with repetitive tasks.
What we will learn about functions:
- What functions are (this page)
- Built-in functions and methods (functions already defined within Python)
- User-defined functions (creating our own functions)
- Modules and packages (external function scripts/files)
There will be a few other topics between 2 and 3, particularly our Rock paper scissors game plan and data types. These topics will show us more applications and examples of built-in functions.