Python quiz questions

Python interview questions

  • 1.

    __________ creates a list.

    1. A. list1 = list()

    2. B. list1 = []

    3. C. list1 = list([12, 4, 4])

    4. D. list1 = [12, 4, 4]

    5. E. list1 = [1, "3", "red"]

    Answer
  • 2.

    Which of following are valid dictionary declarations?

     

    1. dict = {['Name']: 'Sean', 'Age': 8}
    2. dict = {'Name': 'Sean', 'Age': 8}
    3. dict = {1: 'Sean', 'Age': 8}

    Answer
  • 3.

    What is the ouput?

    dict = {'Name': 'Jill', 'Age': 17, 'Name': 'Bill'}
    
    print "dict['Name']: ", dict['Name']
    1. Jill

    2. Bill

    3. Exception

    Answer
  • 4.

    Which of the following is the exponent operator?

    1. $

    2. %

    3. **

    4. *

    Answer
  • 5.

    Study the code given below, and choose the most appropriate answer: 

    a = [1, 4, 20, 2, 5] 
    x = a[0] 
    for i in a: 
        if i > x: 
            x = i 
    print x

     

    1.  

      The value of x is the average of all the number in the list.

    2. The value of x is the smallest number in the list.

    3.  

      The value of x is the largest number in the list.

    4. The value of x is the sum of all the number in the list.

    Answer
  • 6.

    What is the value of x after executing the code shown below?

    i = 0
    x = 0
    while i < 10:
        if i % 2 == 0:
            x += 1
        i += 1
    
    x = _____.

     

    1. 3

    2. 4

    3. 5

    4. 0

    Answer
  • 7.

    What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
    cmd> sample Good Morning

    /* sample.c */
    #include<stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("%d %s", argc, argv[1]);
        return 0;
    }
    1. 3 Good

    2. 2 Good

    3. Good Morning

    4. 3 Morning

    Answer
  • 8.

    What is the output

    myExample = {'someItem': 2, 'otherItem': 20,'newItem':400}
    
    for a in myExample:
        print (a, myExample[a])

     

    1. ('newItem', 400)
      ('otherItem', 20)
      ('someItem', 2)

    2. ('newItem', 402)
      ('otherItem', 20)
      ('someItem', 2)

    3. ('newItem', 400)
      ('otherItem', 20)
      ('someItem', 22)

    4. ('newItem', 400)
      ('otherItem', 22)
      ('someItem', 2)

    Answer
  • 9.

    What is this:

    exec((lambda x:x).func_code.__class__(0,0,0,0,"\x91\x03\x30d\x37\x13",(),(),(),"","",0,""))

     

    1. Some random invalid code

    2. Valid code in python 2

    3. A way to execute python bytecode

    Answer
  • 10.

    a = ?

    a = [[1] * 2] * 2
    a[0][0]=2

     

    1. [[2, 1], [1, 1]]

    2. [[2, 1], [2, 1]]

    3. [[2, 2], [2, 2]]

    Answer
  • 11.

    How to get access to __b_ in outside of class a

    class a:
     __b_="hello"

     

    1. It is impossible

    2. a.__b_

    3. a._a__b_

    Answer
  • 12.

    How to get access to __b__ in outside of class a

    class a:
     __b__="hello"

     

    1. It is impossible

    2. a.__b__

    3. a._a__b__

    Answer
  • 13.

    What will be printed?

    def f(value):
     while True:
      value = (yield value)
    
    a=f(10)
    print(next(a))
    print(next(a))
    print(a.send(20))

     

    1. 10,10

    2. 10,10,20

    3. 10,None,20

    4. 10,None,None

    Answer
  • 14.

    Will "f()" be printed?

    def f():
     print("f()")
     yield 1
    
    f()

     

    1. Yes

    2. No

    Answer
  • 15.

    a = ?

    a = ( 'bay' and 'cat' )

     

    1. True

    2. False

    3. 'bay'

    4. 'cat'

    Answer
  • 16.

    a = ?

    a = {1:'a',2:'b'}=={2:'b',1:'a'}

     

    1. True

    2. False

    3. It causes TypeError

    Answer
  • 17.

    a = ?
     

    a = {1:2,2:3,3:4}<{2:5,3:6,4:7,5:8}

     

    1. True

    2. False

    3. It causes TypeError

    Answer
  • 18.

    a = ?
     

    a = {1:2,2:3,3:4}<{2:5,3:6,4:7,5:8}

     

    1. True

    2. False

    3. It causes TypeError

    Answer
  • 19.

    a = ?

    a = {1,2,3}<{2,3,4,5}

     

    1. True

    2. False

    3. It causes TypeError

    Answer
  • 20.

    a = ?

    a = [1,2,3]>(2,3)

     

    1. True

    2. False

    3. It causes TypeError

    Answer

© 2017 QuizBucket.org