Home / CSE MCQs / Python MCQs :: Python Formatting & Decorators

CSE MCQs :: Python MCQs

  1. The output of the two codes shown below is the same. State whether this statement is true or false.

    bin((2**16)-1)
     '{}'.format(bin((2**16)-1))
  2. A.
    True
    B.
    False
    C.
    Both I and II
    D.
    Only I

  3. What is the output of the code shown below?

    'The {} side {1} {2}'.format('bright', 'of', 'life')
  4. A.
    Error
    B.
    'The bright side of life'
    C.
    'The {bright} side {of} {life}'
    D.
    No output

  5. In the code shown below, which function is the decorator?

    def mk(x):
        def mk1():
            print("Decorated")
            x()
        return mk1
    def mk2():
        print("Ordinary")
    p = mk(mk2)
    p()
  6. A.
    p()
    B.
    mk()
    C.
    mk1()
    D.
    mk2()

  7. What is the output of the code shown below?

    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)
  8. A.

    hello

    NO

    B.

    hello

    Zero Division Error

    C.
    NO
    D.
    hello

  9. What is the output of the code shown below?

    def mk(x):
        def mk1():
            print("Decorated")
            x()
        return mk1
    def mk2():
        print("Ordinary")
    p = mk(mk2)
    p()
  10. A.

    Decorated

    Decorated

    B.

    Ordinary

    Ordinary

    C.

    Ordinary

    Decorated

    D.

    Decorated

    Ordinary


  11. What is the result of the expression shown below if x=56.236?

    print("%.2f"%x)
  12. A.
    56.00
    B.
    56.24
    C.
    56.23
    D.
    0056.236

  13. What is the output of the code shown?

    x=3.3456789
    '%f | %e | %g' %(x, x, x)
  14. A.
    Error
    B.
    '3.3456789 | 3.3456789+00 | 3.345678'
    C.
    '3.345678 | 3.345678e+0 | 3.345678'
    D.
    '3.345679 | 3.345679e+00 | 3.34568'

  15. The output of the code shown below is:

    s='{0}, {1}, and {2}'
    s.format('hello', 'good', 'morning')
  16. A.
    'hello good and morning'
    B.
    'hello, good, morning'
    C.
    'hello, good, and morning'
    D.
    Error