Grouping Logic with Python Functions - Going Beyond an Initial Python Script

Pubblicato il: 07 September 2020
sul canale di: Nick DeRobertis
2,842
58

Grouping Logic with Python Functions

Part of the lecture series "Going Beyond an Initial Python Script":
https://nickderobertis.github.io/fin-...

Full Course Website:
https://nickderobertis.github.io/fin-...


Notes
--------

- Functions are the logical building blocks for any Python program, including our models
- Functions contain a piece of logic which then can be reused flexibly with different inputs
- We have functions in Excel, e.g. =SUM, =IF, =VLOOKUP, but as an Excel user you typically do not define functions. Python has built-in functions and also it is very easy to define your own.
- Ultimately, you should be able to run your entire model by running a single function
- The sub-models should also be functions, and the steps within the sub-models should also be functions. This can be broken into as many layers as is necessary. Your higher-level custom functions will be calling your lower-level custom functions.
- Not only will you have better readability and organization of your model, but also you will be able to reuse logic more often which lowers maintenance costs
- Functions scope the variables defined within. You cannot use those variables outside the function. This lets you use more general variable names which increases readabilityDefault arguments are a great way to keep your function flexible but also easy to use
- For these lab exercise, I have provided cells to check your work. After adding your solution and running the exercise cell, then run the check cell which will throw an AssertionError or NameError if incorrect and nothing if correct.
- The exercises test creating functions with and without default arguments and adding docstrings to functions

Resources
------------

- Python Basics: https://nickderobertis.github.io/fin-...
- Python Basics Lab Exercises: https://nickderobertis.github.io/fin-...
- Python Built-in Functions Official Reference: https://docs.python.org/3/library/fun...


In questa pagina del sito puoi guardare il video online Grouping Logic with Python Functions - Going Beyond an Initial Python Script della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Nick DeRobertis 07 September 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 2,842 volte e gli è piaciuto 58 spettatori. Buona visione!