Python quiz questions

Python interview questions

  • 1.

    What gets printed?

    d = lambda p: p * 2
    t = lambda p: p * 3
    x = 2
    x = d(x)
    x = t(x)
    x = d(x)
    print x
    1. 7

    2. 12

    3. 24

    4. 36

    5. 48

    Answer
  • 2.

    what gets printed? Assuming python version 3.x

    print (type(1/2))
    1. <class 'int'>

    2. <class 'number'>

    3. <class 'float'>

    4. <class 'double'>

    5. <class 'tuple'>

    Answer
  • 3.

    what is the output of the below program?

    a = [1,2,3,None,(),[],]
    print len(a)
    1. syntax error

    2. 4

    3. 5

    4. 6

    5. 7

    Answer
  • 4.

    what is the output of the following code?

    print type(lambda:None)
    1. <type 'NoneType'>

    2. <type 'tuple'>

    3. <type 'type'>

    4. <type 'function'>

    5. <type 'bool'>

    Answer
  • 5.

    what should the below code print?

    print type(1J)
    1. <type 'complex'>

    2. <type 'unicode'>

    3. <type 'int'>

    4. <type 'float'>

    5. <type 'dict'>

    Answer
  • 6.

    what gets printed?

    def f(): pass
    print type(f())
    1. <type 'function'>

    2. <type 'tuple'>

    3. <type 'NoneType'>

    4. <type 'str'>

    5. <type 'type'>

    Answer
  • 7.

    what is the output of the following code?

    print type([1,2])
    1. <type 'tuple'>

    2. <type 'int'>

    3. <type 'set'>

    4. <type 'complex'>

    5. <type 'list'>

    Answer
  • 8.

    what gets printed? Assuming python version 2.x

    print type(1/2)
    1. <type 'int'>

    2. <type 'number'>

    3. <type 'float'>

    4. <type 'double'>

    5. <type 'tuple'>

    Answer
  • 9.

    What does the following code do?

    def a(b, c, d): pass

     

    1. defines a list and initializes it

    2. defines a function, which does nothing

    3. defines a function, which passes its parameters through

    4. defines an empty class

    Answer

© 2017 QuizBucket.org