Why: Nesting, Closure, Decorators & First Class Functions? (W/ Mnemonics)
Channel: Mnemonic Academy
Date: 2017-05-07

Get The Full “Learn Python 🐍” Online Course: 
http://www.mnemonic.academy/learn-python

The following video is from an online educational course produced by Mnemonic Academy that teaches the basics of Python programming using mnemonics, metaphors and the science of learning titled “Learn Python: Like a Bee Student”, taught by instructor Dylan Jorgensen

What is a first class function?
- A first class function is a function that is as malleable as an object, because it is an object.
- When we say Python supports first-class functions we are referring to the idea that functions can be passed into other functions as arguments, stored as variables and event returned from functions.

What are nesting functions?
- Functions are defined with a def func name (): and they need to be called later in the code. Both of these elements are inside just the logic area of the parent function to consider it a nested function. 

What is the syntax?
- When you call the name like a variable without the parenthesis it acts like a variable.
- When you call the name with parenthesis then it runs like calling a function.

What’s a closure?
- A closure is when we package a function together with a snapshot of all the variables it has access to in it’s scope. 
- A closure (unlike a plain function) allows the function to access those captured variables through the closure's reference to them, even when the function is invoked outside their scope.

What’s a decorator?
- It wraps a function (or class). So we can think of them as a special new function that only accepts other functions as arguments.
- However the syntax for this does not look like a normal function call with parentheses, instead it’s syntax is to use an @ symbol above the function.
- It lets you alter code after it‘s executed by passing the result from the first function into a second. Think function return + more.
- Because of closure this new decorator function also has read access to the outer environment that was packaged as part of the inner function.

Photos under creative commons licence are links to the original source from the Learn Python: E-Book. https://goo.gl/BAMwi6, https://goo.gl/K1xRFv, https://goo.gl/9k2MY3

Interested in Learning More About Online Courses That Teach Using Mnemonics, Metaphors and the Science of Learning?

Checkout All Our Mnemonic Academy 🐝 Online Courses: 
http://www.mnemonic.academy

Subscribe To Our Mnemonic Academy 🐝 YouTube Channel:
https://www.youtube.com/channel/UCrZjSLS1o3FJDS5hFoTCIPQ

Like Our Mnemonic Academy 🐝 Facebook Page:
https://www.facebook.com/www.mnemonic.academy