Vidyalelo
Python · all questions

Formatting and Decorators
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

82

Questions

2/5

Page

Pick an option on a question to see the right answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python expression if the value of x is 34?
print(“%f”%x)

Select an option to see the answer and solution.

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.

Select an option to see the answer and solution.

Which module must be imported to use the @abstractmethod decorator in Python?

Select an option to see the answer and solution.

What is the output of the code: print("{:<10}".format("hello"))?

Select an option to see the answer and solution.

The output of the two codes shown below is the same.
i. '{0:.2f}'.format(1/3.0)
ii. '%.2f'%(1/3.0)

Select an option to see the answer and solution.

What will be the output of the following Python code?
'{0:f}, {1:2f}, {2:05.2f}'.format(1.23456, 1.23456, 1.23456)

Select an option to see the answer and solution.

What will be the output of the following Python code?
'{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])

Select an option to see the answer and solution.

The formatting method {1:<10} represents the . . . . . . . . positional argument, . . . . . . . . justified in a 10 character wide field.

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

Identify the decorator in the snippet of code shown below.
def sf():
     pass
sf = mk(sf)
@f
def sf():
     return

Select an option to see the answer and solution.

Which built-in function is used to check if an object is an instance of a particular class?

Select an option to see the answer and solution.

What is the purpose of the @staticmethod decorator compared to the @classmethod decorator?

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=list('HELLO')
'first={0[0]}, third={0[2]}'.format(l)

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
x=3.3456789
'%-6.2f | %05.2f | %+06.1f' %(x, x, x)

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

What will be the output of the python code shown below for various styles of format specifiers?
x=1234
res='integers:...%d...%-6d...%06d' %(x, x, x)
res

Select an option to see the answer and solution.

What will be the output of the following Python code?
t = '%(a)s, %(b)s, %(c)s'
t % dict(a='hello', b='world', c='universe')

Select an option to see the answer and solution.

In Python, which of the following is used to format a string left-justified within a field?

Select an option to see the answer and solution.

What does the ** symbol do when used in a function's parameter list?

Select an option to see the answer and solution.