Python quiz questions

Python interview questions

  • 1.

    Which of the following is not a complex number?

    1. k = 2 + 3j

    2. k = complex(2, 3)

    3. k = 2 + 3l

    4. k = 2 + 3J

    Answer
  • 2.

    What is the output of the following program :

    print 0.1 + 0.2 == 0.3

     

    1. True

    2. False

    3. Machine dependent

    4. Error

    Answer
  • 3.

    Which module in Python supports regular expressions?

    1. re

    2. regex

    3. pyregex
       

    4. None of the above

    Answer
  • 4.

    Given a function that does not return any value, what value is shown when executed at the shell?

    1. int

    2. bool

    3. void

    4. None
       

    Answer
  • 5.

    What is the output of the following program :

    print "Hello World"[::-1]

     

    1. dlroW olleH

    2. Hello Worl

    3. d

    4. Error

    Answer
  • 6.

    What is the output of the following program :

    i = 0
    while i < 3:
           print i
           i++
           print i+1

     

    1. 0 2 1 3 2 4
       

    2. 0 1 2 3 4 5
       

    3. Error

    4. 1 0 2 4 3 5
       

    Answer
  • 7.

    Which operator is overloaded by the or() function?

    1. II

    2. I

    3. //

    4. /

    Answer
  • 8.

    Which function overloads the >> operator?

    1. more()

    2. gt()
       

    3. ge()
       

    4. None of the above
       

    Answer
  • 9.

    What is the output of the following code :

    print 9//2

     

    1. 4.5

    2. 4.5

    3. 4

    4. Error

    Answer
  • 10.

    time.time() returns ________

    1. the current time

    2. the current time in milliseconds

    3. the current time in milliseconds since midnight

    4. the current time in milliseconds since midnight, January 1, 1970

    5. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)

    Answer
  • 11.

    Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?

    1. [3, 4, 5, 20, 5, 25, 1, 3]

    2. [1, 3, 3, 4, 5, 5, 20, 25]

    3. [3, 5, 20, 5, 25, 1, 3]

    4. [1, 3, 4, 5, 20, 5, 25]

    Answer
  • 12.

    What is the output of the following program :

    import re
    sentence = 'horses are fast'
    regex = re.compile('(?P\w+) (?P\w+) (?P\w+)')
    matched = re.search(regex, sentence)
    print(matched.groupdict())

     

    1. {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

    2. (‘horses’, ‘are’, ‘fast’)

    3. ‘horses are fast’

    4. ‘are’

    Answer
  • 13.

    Which of the following is the use of id() function in python?

    1. Id returns the identity of the object

    2. Every object doesn’t have a unique id

    3. All of the mentioned

    4. None of the mentioned

    Answer
  • 14.

    What is called when a function is defined inside a class?

    1. Module

    2. Class

    3. Another Function

    4. Method

    Answer
  • 15.

    What is the output of the following program :
     

    y = 8
    z = lambda x : x * y
    print z(6)

     

    1. 48

    2. 14

    3. 64

    4. None of the above

    Answer
  • 16.

    What is the output of the following segment :
     

    chr(ord('A'))

     

    1. A

    2. B

    3. a

    4. Error

    Answer
  • 17.

    What is the output of the following code :

    L = ['a','b','c','d']
    print "".join(L)

     

    1. Error

    2. None

    3. abcd

    4. [‘a’,’b’,’c’,’d’]

    Answer
  • 18.

    What will be the output of the following code :

    print type(type(int))


     

    1. Error

    2. 0

    3. type 'int'

    4. type 'type'

    Answer
  • 19.

    A certain computation generates two arrays a and b such that a[i]=f(i) for 0 ≤ i < n and b[i]=g(a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.

    Process X:                         Process Y:
    private i;                         private i;
    for (i=0; i < n; i++) {            for (i=0; i < n; i++) {
       a[i] = f(i);                       EntryY(R, S);
       ExitX(R, S);                       b[i]=g(a[i]);
    }                                 }

    Which one of the following represents the CORRECT implementations of ExitX and EntryY?

    (A)

    ExitX(R, S) {
      P(R);
      V(S);
    }
    
    EntryY (R, S) {
      P(S);
      V(R);
    }

    (B)

    ExitX(R, S) {
      V(R);
      V(S);
    }
    
    EntryY(R, S) {
      P(R);
      P(S);
    }

    (C)

    ExitX(R, S) {
      P(S);
      V(R);
    }
    EntryY(R, S) {
      V(S);
      P(R);
    }

    (D)

    ExitX(R, S) {
      V(R);
      P(S);
    }
    EntryY(R, S) {
      V(S);
      P(R);
    }

     

    1. A

    2. B

    3. C

    4. D

    Answer
  • 20.

    A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?

    1. -2

    2. -1

    3. 1

    4. 2

    Answer

© 2017 QuizBucket.org