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

1/5

Page

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

Which function is used to format strings in Python?

Select an option to see the answer and solution.

In Python, what does the % operator do when used for string formatting?

Select an option to see the answer and solution.

Which of the following is an f-string in Python?

Select an option to see the answer and solution.

What will be the output of the following Python expression if x=22.19?
print("%5.2f"%x)

Select an option to see the answer and solution.

The expression shown below results in an error.
print("-%5d0",989)

Select an option to see the answer and solution.

In Python, what does the expression {:.2e} do in a formatted string?

Select an option to see the answer and solution.

What is the purpose of the @wraps decorator in Python's functools module?

Select an option to see the answer and solution.

What will be the output of the following Python code?
s='{0}, {1}, and {2}'
s.format('hello', 'good', 'morning')

Select an option to see the answer and solution.

What will be the output of the following Python code?
'%x %d' %(255, 255)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the primary use of the @staticmethod decorator?

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

In Python, what is the purpose of the @classmethod decorator?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following two codes?
i. '{0}'.format(4.56)
ii. '{0}'.format([4.56,])

Select an option to see the answer and solution.

In Python, what is the purpose of the locals() function?

Select an option to see the answer and solution.

What will be the output of the following Python expression if X=345?
print(“%06d”%X)

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=list('HELLO')
p=l[0], l[-1], l[1:3]
'a={0}, b={1}, c={2}'.format(*p)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
x=3.3456789
'%s' %x, str(x)

Select an option to see the answer and solution.