Functions in Python: Working with Advanced Features of Python Functions
What is recursion?
A function invoking itself within its function body
What is the biggest advantage of the decorator in Python?
Adds functionality to existing code without modifying the code itself
Which of the following statement(s) is/are true about Python decorators?
Can be constructed in such a way that they can be used with functions which have any number of arguments Are built using closure under the hood
Which of the following functions can be written recursively?
Find the Fibonacci series Printing numbers in ascending order
Why would you prefer generator functions over regular lists for generating infinite sequences?
Generators are more memory efficient while generating infinite sequences Infinite sequences cannot fit in a list because it won't fit in Python memory
Which of the following is true about a generator function?
It returns a generator object It has a yield statement rather than a return statement
What are closures?
Nested functions which carry with them local state
Your recursive function call can go on forever till Python terminates it. To fix this you need to:
Specify a clear terminating condition for the recursive call
Which of the following is true about local state and closures?
The local state information associated with a closure remains even if the outer functions is no longer in Python memory
Consider the code below: @decorator_1 @decorator_2 def some_function(): print("Hello") Which of the following statement(s) is/are true?
decorator_2 will be applied to the function first This is referred to as chaining decorators and is valid