Python quiz questions

Python interview questions

  • 1.

    Which thread method is used to wait until it terminates?

    1. None

    2. waitforthread()

    3. wait()

    4. join()

    Answer
  • 2.

    What is the exception raised for an error that doesn’t fall in any of the categories?

    1. ReferenceError

    2. SystemError

    3. RuntimeError

    4. LookupError

    Answer
  • 3.

    What is the method to retrieve the list of all active threads?

    1. getList()

    2. getThreads()

    3. threads()

    4. enumerate()

    Answer
  • 4.

    What is the difference between a semaphore and bounded semaphore?

    1. Semaphore holds a counter for the number of release() calls minus the number of acquire() calls, plus an initial value but bounded semaphore doesn't.

    2. A bounded semaphore makes sure its current value doesn’t exceed its initial value while semaphore doesn't.

    3. Bounded semaphore holds a counter for the number of release() calls minus the number of acquire() calls, plus an initial value but semaphore doesn't.

    4. A semaphore makes sure its current value doesn’t exceed its initial value while bounded semaphore doesn't.

    Answer
  • 5.

    How does global value mutation used for thread-safety?

    1. None

    2. via Mutex

    3. via GIL (Global Interpreter Lock)

    4. via Locking

    Answer
  • 6.

    What are the states/features supported by a RLock object?

    1. Recursion level

    2. Unlocked

    3. Locked

    4. Owning thread

    Answer
  • 7.

    Which method is used to identify a thread?

    1. get_ident()

    2. getThread()

    3. None

    4. getName()

    Answer
  • 8.

    Which of the following statements best describes the behavior of the random.shuffle(mylist) as being used in the below code fragment?

    import random
    mylist = [10, 20, 30]
    random.shuffle(mylist)
    print(mylist)
    1. It'll not modify the list. This function is just a placeholder and yet to be implemented.

    2. shuffle the elements of the list in-place.

    3. return a list where elements 10, 20 and 30 would be at random positions.

    4. shuffle the elements for the no. of times equal to the size of the list.

    Answer
  • 9.

    Which of the following is the output of the below piece of code?

    import random
    print(random.seed(3))
    1. Null

    2. Error

    3. None

    4. None of the mentioned

    5. 3

    Answer
  • 10.

    Which of the following is the output of the below Python code snippet?

    ints = set([1,1,2,3,3,3,4])
    print(len(ints))
    1. 1

    2. 4

    3. 5

    4. 7

    Answer
  • 11.

    Which of the following is the output of the instructions given below?

    mylist=[1, 5, 9, int('0')]
    print(sum(mylist))
    1. 16

    2. 5

    3. 1

    4. 15

    5. 63

    6. None of the mentioned

    Answer
  • 12.

    Which of the following is the output of the below Python code?

    mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
    print(mylist[:-1])
    1. aaaaaabbb

    2. [a, aa, aaa, b, bb]

    3. ['a', 'aa', 'aaa', 'b', 'bb', 'bbb']

    4. ['a', 'aa', 'aaa', 'b', 'bb']

    5. None of the mentioned

    6. Error

    Answer
  • 13.

    Which of the following for loops would yield the below number pattern?
    Note: Python 2.7

    11111
    22222
    33333
    44444
    55555
    1. for i in range(1, 6):
       print(i, i, i, i, i)
    2. for i in range(1, 5):
       print(str(i) * 5)
    3. for i in range(1, 6):
       print(str(i) * 5)
    4. for i in range(0, 5):
       print(str(i) * 5)
    Answer
  • 14.

    Which of the following is the output of the code given below?

    mylist=['abc','cde','abcde','efg']
    print(max(mylist))
    1. abcde

    2. efg

    3. abc

    4. cde

    5. 'abcde'

    6. "abcde"

    Answer
  • 15.

    Which of the following is the output of the Python code fragment given below?

    var1 = 4.5
    var2 = 2
    print(var1//var2)
    1. 2.5

    2. 2.0

    3. 22.5

    4. 2.25

    5. 20.0

    Answer
  • 16.

    Which of the following is the output of the below Python code?

    try:
     if '1' != 1:
      raise "firstError"
     else:
      print("firstError has not occured")
    except "firstError":
     print("firstError has occured")
    1. firstError has occured

    2. firstError has not occured

    3. TypeError occurs

    4. ValueError occurs

    Answer
  • 17.

    Which of the following is the output of the below Python code?
    [Note: Python 2.7.5 and above]

    mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
    print(mylist[int(-1/2)])
    1. b

    2. 'bbb'

    3. bbb

    4. aaa

    5. a

    6. None of the mentioned

    Answer
  • 18.

    Which of the following is the output of the below Python code?

    var1 = lambda var: var * 2
    ret = lambda var: var * 3
    result = 2
    result = var1(result)
    result = ret(result)
    result = var1(result)
    print(result)
    1. 12

    2. 36

    3. 24

    4. 7

    5. 48

    Answer
  • 19.

    Which of the following is the output of the lines of code specified below?

    x = 1
    print(++++x)
    1. 1

    2. 2

    3. 3

    4. 4

    Answer
  • 20.

    Which of the following correctly describes the output of the below Python code?

    testArr = [11, 22, 33, 22, 11] 
    result = testArr[0] 
    for iter in testArr: 
     if iter > result: 
      result = iter
    print(result)
    1. result is the smallest number in the list.

    2. result is the average of all the number in the list.

    3. result is the sum of all the number in the list.

    4. result is the largest number in the list.

    5. None of these

    Answer

© 2017 QuizBucket.org