/  Python-Decorators-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1. Which function is the decorator in the below Python code?
def mk(x):
    def mk1():
        print("Decorated")
        x()
   return mk1
def mk2():
   print("Ordinary")
p = mk(mk2)
p()
p( )
mk( )
mk1( )
mk2( )

Correct!

Wrong!

2. What will be the output of the following Python code?
def ordi():
   print("Ordinary")
print(ordi)
ordi()
Address and Ordinary
Error and Address
Ordinary and Ordinary
Ordinary and Address

Correct!

Wrong!

3. Are the below Python codes being equivalent?
CODE 1
  @fdef f1():
        print(“Hello”)
CODE 2
  def f1():
       print(“Hello”)
f1 = f(f1)
True
False

Correct!

Wrong!

4. What will be the output of the following Python code?
def c(f):
    def inner(*args, **kargs):
       inner.co += 1
        return f(*args, **kargs)
   inner.co = 0
    return inner
@c
def fnc():
    passif __name__ == '__main__':
   fnc()
    fnc()
   fnc()
 print(fnc.co)
4
3
0
1

Correct!

Wrong!

5. What will be the output of the following Python code?
def d(f):
    def n(*args):
        return '$' + str(f(*args))
    return n
@d
def p(a, t):
    return a + a*t
print(p(100,0))
100
0
$0
$100

Correct!

Wrong!

6. What will be the output of the following Python code?
class A:
   @staticmethod
    def a(x):
        print(x)
A.a(100)
Error
Warning
100
No output

Correct!

Wrong!

7. Which is the decorator in the below Python code?
def sf():
     passs
f = mk(sf)
@f
def sf():
    return
@f
f
sf( )
mk

Correct!

Wrong!

8. What will be the output of the following Python code?
def f(x):
    def f1(*args, **kwargs):
       print("*", 5)
       x(*args, **kwargs)
        print("*", 5)
    return f1
@f
def p(m):
   p(m)
print("hello")
*****
hello
***** and hello
***** and hello hello

Correct!

Wrong!

9. The following python code can work with how many parameters.
def f(x):
    def f1(*args, **kwargs):
           print("I2tutorials")
           return x(*args, **kwargs)
    return f1
2
1
any number of
0

Correct!

Wrong!

10. What will be the output of the following Python function?
def f(p, q):
         return p%q
f(0, 2)
f(2, 0)
0; 0
Zero Division Error; Zero Division Error
0; Zero Division Error
Zero Division Error; 0

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Decorators-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...