How to create methods in Python
• 1 minPython will allow you to create your own methods.
What I mean by methods are pieces of code that you can re-use multiple times.
You will define it once within your main script and will be able run it multiple times, with different parameters.
Here is an example
Here is an example of a method that I use quite often.
Passing parameters to the method
In order for the method to process information, a good way to send them data is through the use of parameters.
Here is an example with three parameters:
A real life situation
So imagine you are working on a project that requires you to list the csv files contained in a specific folder. (e.g. sales of your e-commerce that has been splitted in files per month) see below.
current_dir/
├── my_script.py
└── data
├── january.csv
└── february.csv
Here you are !
You can now reuse this method in other projects without running into problems.