Python quiz questions

Python interview questions

  • 1.

    What does the below code intended to do?

    def a(b, c, d):
       pass
    1. defines a set and initializes it.

    2. defines a function, which does nothing.

    3. defines an empty class.

    4. defines a method, which passes its parameters through.

    Answer
  • 2.

    Which function does in-place reversal of objects in a list?

    1. list.pop(obj=list[-1])

    2. list.remove(obj)

    3. list.sort([func])

    4. list.reverse()

    Answer
  • 3.

    What gets printed as the output of the below code?

    x = True
    y = False
    z = False
    if not x or y:
        print 1
    elif not x or not y and z:
        print 2
    elif not x or y or not y and x:
        print 3
    else:
        print 4
    1. 1

    2. 4

    3. 2

    4. 3

    Answer
  • 4.

    What is the output of the following Python code?

    tinytuple = (123, 'techbeamers')
    print tinytuple * 2
    1. (123, 'techbeamers') * 2

    2. (123, 'techbeamers', 123, 'techbeamers')

    3. None of the above

    4. Error

    Answer
  • 5.

    What would be the result of the following expression in Python?

    print 3/5
    1. 0.6

    2. 0

    3. 6/10

    4. None of the above

    Answer
  • 6.

    What is the output of the below Python code?

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

    2. 6

    3. 4

    4. syntax error

    Answer
  • 7.

    If the following statement is run in Python, what will be the result?

    print abc
    1. =abc

    2. 'abc'

    3. NameError: name 'abc' is not defined

    4. abc

    Answer
  • 8.

    What is the output of the following code?

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

    2. <type 'type'>

    3. <type 'NoneType'>

    4. <type 'tuple'>

    Answer
  • 9.

    What is the output of following code?

    list = [ 'Tech', 404, 3.03, 'Beamers', 33.3 ]
    print list[1:3]
    1. [ 'Tech', 404, 3.03, 'Beamers', 33.3 ]

    2. [404, 3.03]

    3. ['Tech', 'Beamers']

    4. None of the above

    Answer
  • 10.

    If the following code is run in Python, what would be the result?

    num = '5'*'5'
    1. 333

    2. 27

    3. 9

    4. TypeError: can't multiply sequence by non-int of type 'str'

    Answer
  • 11.

    Which of the following functions print the output to the console?

    1. console.log

    2. print

    3. output

    4. echo

    Answer
  • 12.

    Is the following statement correct?

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

    1. True

    2. False

    Answer
  • 13.

    What is the output of the following code?

    import re
    sentence = 'Learn Python Programming'
    test = re.match(r'(.*) (.*?) (.*)', sentence)
    print(test.group())
    1. (‘Learn’, ‘Programming’)

    2. (Learn, Python, Programming)

    3. Learn Python Programming

    4. ‘Learn Python Programming’

    Answer
  • 14.

    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
  • 15.

    Which module in Python supports regular expressions?

    1. pyregex

    2. regex

    3. re

    4. None

    Answer
  • 16.

    what should the below code print?

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

    2. <type 'float'>

    3. <type 'unicode'>

    4. <type 'complex'>

    Answer
  • 17.

    What is the value of colors[2]?

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

    2. indigo

    3. blue

    4. yellow

    Answer
  • 18.

    Is the following statement correct?

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

    1. True

    2. False

    Answer
  • 19.

    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
  • 20.

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

    1. PYTHONSTARTUP

    2. PYTHONCASEOK

    3. PYTHONPATH

    4. PYTHONHOME

    Answer

© 2017 QuizBucket.org