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)
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
Answer: Option B
Related Questions on Formatting and Decorators
Which function is used to format strings in Python?
A. format()
B. stringify()
C. format_string()
D. str_format()
In Python, what does the % operator do when used for string formatting?
A. Substitutes variables
B. Raises an error
C. Performs division
D. Calculates exponentiation
Which of the following is an f-string in Python?
A. f"Hello {name}"
B. "Hello {}".format(name)"
C. "Hello %s" % name
D. format("Hello {}", name)
What will be the output of the following Python expression if x=22.19?
print("%5.2f"%x)
A. 22.1900
B. 22.00000
C. 22.19
D. 22.20

Join The Discussion