133). What will be the output of the following Python code?
def mk(x):
    def mk1():
        print("Decorated")
        x()
    return mk1
def mk2():
    print("Ordinary")
p = mk(mk2)
p()

[A]Decorated Decorated
[B]Ordinary Ordinary
[C]Ordinary Decorated
[D]Decorated Ordinary

Show Answer

134). In the following Python code, which function is the decorator?
def mk(x):
    def mk1():
        print("Decorated")
        x()
    return mk1
def mk2():
    print("Ordinary")
p = mk(mk2)
p()

[A]p()
[B]mk()
[C]mk1()
[D]mk2()

Show Answer

135). The ______ symbol along with the name of the decorator function can be placed above the definition of the function to be decorated works as an alternate way for decorating a function.
def mk(x):
    def mk1():
        print("Decorated")
        x()
    return mk1
def mk2():
    print("Ordinary")
p = mk(mk2)
p()

[A]#
[B]$
[C]@
[D]&

Show Answer

136). What will be the output of the following Python code?
def ordi():
	print("Ordinary")
ordi
ordi()

[A]Address Ordinary
[B]Error Address
[C]Ordinary Ordinary
[D]Ordinary Address

Show Answer

137). The two snippets of the following Python codes are equivalent.
CODE 1
  @f
def f1():
        print(“Hello”)
CODE 2
  def f1():
         print(“Hello”)
f1 = f(f1)

[A]True
[B]False
[C]0
[D]1

Show Answer

138). What will be the output of the following Python function?
def f(p, q):
	return p%q
f(0, 2)
f(2, 0)

[A]0 0
[B]Zero Division Error Zero Division Error
[C]0 Zero Division Error
[D]Zero Division Error 0

Show Answer

139). What will be the output of the following Python code?
def f(x):
    def f1(a, b):
        print("hello")
        if b==0:
            print("NO")
            return
        return f(a, b)
    return f1
@f
def f(a, b):
    return a%b
f(4,0)

[A]hello NO
[B]hello Zero Division Error
[C]NO
[D]hello

Show Answer

140). 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
def a(x):
    def f1(*args, **kwargs):
        print("%"* 5)
        x(*args, **kwargs)
        print("%"* 5)
    return f1
@f
@a
def p(m):
    print(m)
p("hello")

[A]***** %%%%% hello %%%%% *****
[B]Error
[C]*****%%%%%hello%%%%%*****
[D]hello

Show Answer

141). The following python code can work with ____ parameters.
def f(x):
    def f1(*args, **kwargs):
           print("Sanfoundry")
           return x(*args, **kwargs)
    return f1

[A]2
[B]1
[C]any number of
[D]0

Show Answer

142). 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")

[A]***** hello
[B]***** ***** hello
[C]*****
[D]hello

Show Answer

143). A function with parameters cannot be decorated.
def f(x):
    def f1(*args, **kwargs):
        print("*", 5)
        x(*args, **kwargs)
        print("*", 5)
    return f1
@f
def p(m):
    p(m)
print("hello")

[A]True
[B]False
[C]0
[D]1

Show Answer

144). 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

Show Answer

145). 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

Show Answer

146). 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))

[A]100
[B]$100
[C]$0
[D]0

Show Answer

147). 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():
    pass
if __name__ == '__main__':
    fnc()
    fnc()
    fnc()
    print(fnc.co)

[A]4
[B]3
[C]0
[D]1

Show Answer