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

Publicado el: 07 September 2020
en el canal de: 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...


En esta página del sitio puede ver el video en línea Grouping Logic with Python Functions - Going Beyond an Initial Python Script de Duración hora minuto segunda en buena calidad , que subió el usuario Nick DeRobertis 07 September 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 2,842 veces y le gustó 58 a los espectadores. Disfruta viendo!