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

4/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 snippet?
X=”hi”
print(“05d”%X)

Select an option to see the answer and solution.

A function with parameters cannot be decorated.

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

The output of which of the codes shown below will be: "There are 4 blue birds."?

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
'%d %s %g you' %(1, 'hello', 4.0)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

The output of the two codes shown below is the same.
i. bin((2**16)-1)
ii. '{}'.format(bin((2**16)-1))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which symbol is used to denote a decorator in Python syntax?

Select an option to see the answer and solution.

Which decorator is used to cache the results of a function call in Python?

Select an option to see the answer and solution.

What will be the output of the following Python code?
'%s' %((1.23,),)

Select an option to see the answer and solution.

What is the primary purpose of the functools.partial function in Python?

Select an option to see the answer and solution.

Which of the following is used to format a string with left-aligned text within a field?

Select an option to see the answer and solution.

What will be the output of the following Python expression if x=456?
print("%-06d"%x)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
'The {} side {1} {2}'.format('bright', 'of', 'life')

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
a='hello'
q=10
vars()

Select an option to see the answer and solution.

In Python, what does the expression {:#x} do in a formatted string?

Select an option to see the answer and solution.

Which format specifier is used to represent an integer in binary form in a formatted string?

Select an option to see the answer and solution.