Python Advanced Quiz Questions With Answers

15 Questions | Total Attempts: 5834

SettingsSettingsSettings
Python Advanced Quiz Questions With Answers - Quiz

If you are a programmer then you must have some knowledge of python. Try this ' python advanced quiz questions with answers' and get to test your python knowledge today! Are you just getting into programming and have recently started studying advanced python? Don't worry. It is an easy and interesting subject. Take this quiz to revise your concepts and you might also get to know what areas you need to study more on. All the best!


Questions and Answers
  • 1. 
    What gets printed? def print_header(str):     print "+++%s+++" % str     print_header.category = 1 print_header.text = "some info"   print_header("%d %s" %  \ (print_header.category, print_header.text))
    • A. 

      +++1 some info+++

    • B. 

      +++%s+++

    • C. 

      1

    • D. 

      Some info

  • 2. 
    What gets printed? names1 = ['Amir', 'Barry', 'Chales', 'Dao'] names2 = [name.lower() for name in names1]   print names2[2][0]
    • A. 

      I

    • B. 

      A

    • C. 

      C

    • D. 

      C

    • E. 

      An exception is thrown

  • 3. 
    What gets printed? names1 = ['Amir', 'Barry', 'Chales', 'Dao']   loc = names1.index("Edward")   print loc
    • A. 

      -1

    • B. 

      0

    • C. 

      4

    • D. 

      Edward

    • E. 

      An exception is thrown

  • 4. 
     Assuming the filename for the code below is /usr/lib/python/person.py and the program is run as:  python /usr/lib/python/person.py  What gets printed? class Person:     def __init__(self):         pass       def getAge(self):         print __name__   p = Person() p.getAge()
    • A. 

      Person

    • B. 

      GetAge

    • C. 

      Usr.lib.python.person

    • D. 

      __main__

    • E. 

      An exception is thrown

  • 5. 
    What gets printed? import re sum = 0   pattern = 'back' if re.match(pattern, 'backup.txt'):     sum += 1 if re.match(pattern, 'text.back'):     sum += 2 if re.search(pattern, 'backup.txt'):     sum += 4 if re.search(pattern, 'text.back'):     sum += 8   print sum
    • A. 

      3

    • B. 

      7

    • C. 

      13

    • D. 

      14

    • E. 

      15

  • 6. 
    What numbers get printed import pickle   class account:         def __init__(self, id, balance):                self.id = id                self.balance = balance         def deposit(self, amount):                self.balance += amount         def withdraw(self, amount):                self.balance -= amount   myac = account('123', 100) myac.deposit(800) myac.withdraw(500)   fd = open( "archive", "w" ) pickle.dump( myac, fd) fd.close()   myac.deposit(200) print myac.balance   fd = open( "archive", "r" ) myac = pickle.load( fd ) fd.close()   print myac.balance
    • A. 

      500 300

    • B. 

      500 500

    • C. 

      600 400

    • D. 

      600 600

    • E. 

      300 500

  • 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)
    • A. 

      None None

    • B. 

      None 11

    • C. 

      11 None

    • D. 

      11 11

    • E. 

      Error is generated by program

  • 8. 
    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)
    • A. 

      True

    • B. 

      False

  • 9. 
    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
    • A. 

      1

    • B. 

      2

    • C. 

      3

    • D. 

      4

  • 10. 
    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()
    • A. 

      True

    • B. 

      False

  • 11. 
    What gets printed? kvps  = {"user","bill", "password","hillary"}   print kvps['password']
    • A. 

      User

    • B. 

      Bill

    • C. 

      Password

    • D. 

      Hillary

    • E. 

      Nothing. Python syntax error

  • 12. 
    What gets printed? def simpleFunction():     "This is a cool simple function that returns 1"     return 1   print simpleFunction.__doc__[10:14]
    • A. 

      SimpleFunction

    • B. 

      Simple

    • C. 

      Func

    • D. 

      Function

    • E. 

      Cool

  • 13. 
    What gets printed? import re sum = 0   pattern = 'back' if re.match(pattern, 'backup.txt'):     sum += 1 if re.match(pattern, 'text.back'):     sum += 2 if re.search(pattern, 'backup.txt'):     sum += 4 if re.search(pattern, 'text.back'):     sum += 8   print sum
    • A. 

      3

    • B. 

      7

    • C. 

      13

    • D. 

      14

    • E. 

      15

  • 14. 
    What gets printed (with python version 3.X) assuming the user enters the following at the prompt? #: foo    a = input("#: ")   print a
    • A. 

      F

    • B. 

      Foo

    • C. 

      Not a number

    • D. 

      An exception is thrown

  • 15. 
    What gets printed?   class NumFactory:     def __init__(self, n):         self.val = n     def timesTwo(self):         self.val *= 2     def plusTwo(self):         self.val += 2   f = NumFactory(2) for m in dir(f):     mthd = getattr(f,m)     if callable(mthd):         mthd()   print f.val
    • A. 

      2

    • B. 

      4

    • C. 

      6

    • D. 

      8

    • E. 

      An exception is thrown

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.