Python quiz questions

Python interview questions

  • 1.

    What sequence of numbers is printed?

    values = [1, 2, 1, 3]
    nums = set(values)
    
    def checkit(num):
        if num in nums:
            return True
        else:
            return False
    
    for i in  filter(checkit, values):
        print i
    1. 1 2 3

    2. 1 2 1 3

    3. 1 2 1 3 1 2 1 3

    4. 1 1 1 1 2 2 3 3

    5. Syntax Error

    Answer
  • 2.

    Which numbers are printed?

    for i in  range(2):
        print i
    
    for i in range(4,6):
        print i
    1. 2, 4, 6

    2. 0, 1, 2, 4, 5, 6

    3. 0, 1, 4, 5

    4. 0, 1, 4, 5, 6, 7, 8, 9

    5. 1, 2, 4, 5, 6

    Answer
  • 3.

    What gets printed?

    name = "snow storm"
    
    name[5] = 'X'
    
    print name
    1. snow storm

    2. snowXstorm

    3. snow Xtorm

    4. ERROR, this code will not run

    Answer
  • 4.

    What gets printed?

    name = "snow storm"
    
    print "%s" % name[6:8]
    1. st

    2. sto

    3. to

    4. tor

    5. Syntax Error

    Answer
  • 5.

    What gets printed?

    class Account:
        def __init__(self, id):
            self.id = id
            id = 666 
    
    acc = Account(123)
    print acc.id
    1. None

    2. 123

    3. 666

    4. SyntaxError, this program will not run

    Answer
  • 6.

    What gets printed?

    kvps  = {"user","bill", "password","hillary"}
    
    print kvps['password']
    1. user

    2. bill

    3. password

    4. hillary

    5. Nothing. Python syntax error

    Answer
  • 7.

    What gets printed?

    class parent:
        def __init__(self, param):
            self.v1 = param
    
    class child(parent):
        def __init__(self, param):
            self.v2 = param
    
    obj = child(11)
    print "%d %d" % (obj.v1, obj.v2)
    1. None None

    2. None 11

    3. 11 None

    4. 11 11

    5. Error is generated by program

    Answer
  • 8.

    What gets printed?

    print 0xA + 0xa
    1. 0xA + 0xa

    2. 0xA 0xa

    3. 14

    4. 20

    5. 0x20

    Answer
  • 9.

    What gets printed?

    print "\x48\x49!"
    1. \x48\x49!

    2. 4849

    3. 4849!

    4.       48      49!

    5. HI!

    Answer
  • 10.

    What gets printed?

    Assume Python 2

    print "hello" 'world'
    1. on one line the text: hello world

    2. on one line the text: helloworld

    3. hello on one line and world on the next line

    4. syntax error, this python program will not run

    Answer
  • 11.

    What gets printed?

    print r"\nwoow"
    1. new line then the string: woow

    2. the text exactly like this: r"\nwoow"

    3. the text like exactly like this: \nwoow

    4. the letter r and then newline then the text: woow

    5. the letter r then the text like this: nwoow

    Answer
  • 12.

    What gets printed?

    counter = 1 
    
    def doLotsOfStuff():
        
        global counter
    
        for i in (1, 2, 3): 
            counter += 1
    
    doLotsOfStuff()
    
    print counter
    1. 1

    2. 3

    3. 4

    4. 7

    5. None of them

    Answer
  • 13.

    Assuming python 2.6 what gets printed?

    f = None
    
    for i in range (5):
        with open("data.txt", "w") as f:
            if i > 2:
                break
    
    print f.closed
    1. True

    2. False

    3. None

    Answer
  • 14.

    The following code will successfully print the days and then the months

    daysOfWeek = ['Monday',
                  'Tuesday',
                  'Wednesday',
                  'Thursday',
                  'Friday',
                  'Saturday',
                  'Sunday']
    
    months =             ['Jan', \
                          'Feb', \
                          'Mar', \
                          'Apr', \
                          'May', \
                          'Jun', \
                          'Jul', \
                          'Aug', \
                          'Sep', \
                          'Oct', \
                          'Nov', \
                          'Dec']
    
    print "DAYS: %s, MONTHS %s" % 
        (daysOfWeek, months)
    1. true

    2. false

    Answer
  • 15.

    In python 2.6 or earlier, the code will print error type 1 if accessSecureSystem raises an exception of either AccessError type or SecurityError type

    try:
      accessSecureSystem()
    except AccessError, SecurityError:
      print "error type 1"
    
    continueWork()
    1. true

    2. false

    Answer
  • 16.

    If PYTHONPATH is set in the environment, which directories are searched for modules?

    A) PYTHONPATH directory
    
    B) current directory
    
    C) home directory
    
    D) installation dependent default path
    1. A only

    2. A and D

    3. A, B, and C

    4. A, B, and D

    5. A, B, C, and D

    Answer
  • 17.

    What gets printed?

    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. 2

    3. 3

    4. 4

    Answer
  • 18.

    What gets printed?

    x = True
    y = False
    z = False
    
    if x or y and z:
        print "yes"
    else:
        print "no"
    1. yes

    2. no

    3. No compile

    Answer
  • 19.

    What gets printed?

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

    2. 2

    3. 4

    4. 5

    5. 7

    Answer
  • 20.

    What gets printed?

    x = 4.5
    y = 2
    print x//y
    1. 2.0

    2. 2.25

    3. 9.0

    4. 20.25

    5. 21

    Answer

© 2017 QuizBucket.org