Q: A function with parameters cannot be decorated.
Solution: Any function, irrespective of whether or not it has parameters can be decorated. Hence the statement is false.
Q: Identify the decorator in the snippet of code shown below. def sf(): pass sf = mk(sf) @f def sf(): return
Solution: In the code shown above, @sf is not a decorator but only a decorator line. The ‘@’ symbol represents the application of a decorator. The decorator here is the function mk.
Q: What will be the output of the following Python code? class A: @staticmethod def a(x): print(x) A.a(100)
Solution: The code shown above demonstrates rebinding using a static method. This can be done with or without a decorator. The output of this code will be 100.
You Have Score    | /3 |