Python Decorators Quiz
FREE Online Courses: Transform Your Career – Enroll for Free!
Quiz Summary
0 of 10 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 10 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 10
1. Question
What symbol is used to decorate a function?
CorrectIncorrect -
Question 2 of 10
2. Question
Decorators do not modify a function ______.
CorrectIncorrect -
Question 3 of 10
3. Question
Which of the following statements is true?
CorrectIncorrect -
Question 4 of 10
4. Question
Which of the following statement(s) is/are true?
Statement 1: Nested functions are functions that are defined inside another function
Statement 2: Nested functions can access variables of the enclosing scope
CorrectIncorrect -
Question 5 of 10
5. Question
What type of arguments are used to create general-purpose decorators?
CorrectIncorrect -
Question 6 of 10
6. Question
Identify the decorator function in the below code.
Code
def func1(func):
def func2():
return func()
return func2
def func3():
return “Hello World!”
func3 = func1(func3)
print(func3())
CorrectIncorrect -
Question 7 of 10
7. Question
Identify the function which can be used as a general-purpose decorator in the below code.
Code
def func1(func):
def func2(*args, **kwargs):
print(“Running the function with following arguments”)
print(args, kwargs)
return func(*args, **kwargs)
return func2
def func3(func):
def func4():
return func
func4()
return func4
CorrectIncorrect -
Question 8 of 10
8. Question
What is the output of the below code?
Code
def check_zero(func):
def wrap(num1, num2):
if num2 == 0:
return “Undefined”
return func(num1, num2)
return wrap
def div(a, b):
return a/b
div = check_zero(div)
print(div(div(4, 2), div(0, 10)))
CorrectIncorrect -
Question 9 of 10
9. Question
What is the output of the below code?
Code
def func1(func):
def inner_func(*args, **kwargs):
li = [pow(x, 2) for x in args]
return func(li, **kwargs)
return inner_func
@func1
def func2(li):
return li
@func1
def func3(li):
return [pow(x, 0.5) for x in li]
def func4():
print(func2(1, 2, 3, 4), func3(1, 2),
func2(1, 2), func3(1, 2, 3, 4))
func4()
CorrectIncorrect -
Question 10 of 10
10. Question
What is the output of the below code?
Code
def funcB(func):
def wrap():
print(2)
return func()
return wrap
def funcC(func):
def wrap():
print(3)
return func()
return wrap
@funcB
@funcA
@funcC
def main():
print(“Function”)
main()
CorrectIncorrect