Effective Functions Flashcards
What does it mean that functions are first class objects?
You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions.
What is the correlation between a function and its name?
Totally different def yell: print(blabla) bark=yell print(bark.\_\_name\_\_) >>"yell"
Why is important the fact that you can pass functions as arguments to other functions?
Due to the fact that passing a function means passing a behavior
What is a lexical closure?
Lexical closure is the closure which remembers its lexical scope even if its not currently at that scope.
All functions are objects, but does the reverse hold?
No. All objects are not functions but they can made callabe using __call__ method.
What is a lambda keyword?
It is a keyword required to create small anonymous functions.
add= lambda x,y:x+y
print(add(32,43))
What is the difference between lambdas and functions>
lambdas do not have a return statement.expression
That’s why some people refer to lambdas as single expression functions.
What is the power of the decorator?
The power of decorator lies upon the fact that it can extend the behavior of the callable without the need of modifying it.
What is a decorator?
A decorator is a callable that takes as argument a function and returns a function.
What args and kargs arguments?
They allow a function to take optional arguments.
*Args expands optional arguments as a tuple.
What is function argument unpacking?
Let's say you have a function with the following signature/. def print_vector(x,y,z): print(f'x:{x},y:{y},z:{z}')
if having a list with three elements, instead of passing each element separately, you can use list unpacking operator to simply do the following:
print_vector(*list)