Python quiz questions

Python interview questions

  • 1.

    What does the function re.match do?

    1. matches a pattern at any position in the string

    2. matches a pattern at the start of the string

    3. such a function does not exist

    4. none of the above

    Answer
  • 2.

    Which module in Python supports regular expressions?

    1. pyregex

    2. regex

    3. re

    4. None

    Answer
  • 3.

    what should the below code print?

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

    2. <type 'float'>

    3. <type 'unicode'>

    4. <type 'complex'>

    Answer
  • 4.

    What is the value of colors[2]?

    colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
    1. orange

    2. indigo

    3. blue

    4. yellow

    Answer
  • 5.

    Is the following statement correct?

    There are two types of values in Python: numbers and strings.

    1. True

    2. False

    Answer
  • 6.

    Which of the following function checks that all characters of a string are in upper case?

    1. isupper()

    2. ljust(width[, fillchar])

    3. len(string)

    4. join(seq)

    Answer
  • 7.

    Which of the following environment variable for Python is an alternative module search path?

    1. PYTHONSTARTUP

    2. PYTHONCASEOK

    3. PYTHONPATH

    4. PYTHONHOME

    Answer
  • 8.

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

    1. Unlocked

    2. Locked

    3. Owning thread

    4. Recursion level

    Answer
  • 9.

    How does run() method is invoked?

    1. By Thread.run()

    2. By Thread.create()

    3. None

    4. By Thread.start()

    Answer
  • 10.

    Which one is reentrant lock type?

    1. Lock

    2. RLock

    3. Condition

    4. Semaphore

    Answer
  • 11.

    What is the difference between threading.Lock and threading.RLock?

    1. Lock is owned by a thread while RLock is owned by many.

    2. Lock is owned by none while RLock is owned by many.

    3. Lock and RLock both primitives are owned by many.

    4. Lock and RLock both primitives are owned by a single thread.

    Answer
  • 12.

    What are the lock types a Condition object can associate with?

    1. Lock object

    2. Semaphore

    3. RLock object

    4. None

    Answer
  • 13.

    How to terminate a blocking thread?

    1. None

    2. thread.stop()

    3. thread.stop() & thread.wait()

    4. thread.terminate()

    Answer
  • 14.

    Which synchronization method is used to guard the resources with limited capacity, e.g. a database server?

    1. Lock

    2. Condition

    3. Event

    4. Semaphore

    Answer
  • 15.

    What is the method that wakes up all thread waiting for the condition?

    1. notify()

    2. notifyAll()

    3. release()

    4. releaseAll()

    Answer
  • 16.

    What would be the impact of multithreading on a uni-processor system?

    1. Increase throughput

    2. Degrade performance

    3. Improve performance

    4. Reduce execution time

    Answer
  • 17.

    How to detect the status of a python thread?

    1. isDaemon()

    2. isAlive()

    3. isActive()

    4. None

    Answer
  • 18.

    Which statements are true for RLock objects?

    1. if another thread owns the lock, acquire() will block until the lock is unlocked.

    2. If a thread already owns the lock, acquire() will increment the recursion level by one, and return immediately.

    3. If a thread already owns the lock, acquire() will block until the lock is unlocked.

    4. if another thread owns the lock, acquire() will increment the recursion level by one, and return immediately.

    Answer
  • 19.

    What are the libraries in Python that support threads?

    1. thread

    2. _threading

    3. threading

    4. None

    Answer
  • 20.

    Which Python library runs a function as thread?

    1. threading

    2. None

    3. thread

    4. _threading

    Answer

© 2017 QuizBucket.org