Test Series - python

Test Number 16/108

Q: A function with parameters cannot be decorated.
A. True
B. False
C. 
D. 
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
A. @f
B. f
C. sf()
D. mk
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)
A. Error
B. Warning
C. 100
D. No output
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