Python interview questions and answers

comp.lang.python group recently had a discussion on which interview questions to ask a candidate, with Tim Chase suggesting the following list (redacted from original to include just Python-related material). As you can see, some generic programming questions and some process questions made the list:

  1. Do they know a tuple/list/dict when they see it?
  2. When to use list vs. tuple vs. dictionary vs. set?
  3. Can they use list comprehensions (and know when not to abuse them?)
  4. Can they use tuple unpacking for assignment?
  5. String building. Do they use “+=” or do they build a list and use .join() to recombine them efficiently?
  6. Truth-value testing questions and observations (do they write “if x == True” or do they just write “if x”)?
  7. Basic file-processing (iterating over a file’s lines)
  8. Basic understanding of exception handling
  9. Questions about the standard library (”do you know if there’s a standard library for doing X?”, or “in which library would you find [common functionality Y]?”) Most of these are related to the more common libraries such as os/os.path/sys/re/itertools
  10. Questions about iterators/generators
  11. Questions about map/reduce/sum/etc family of functions
  12. Questions about “special” methods (__foo__)
  13. Can they manipulate functions as first-class objects (Python makes it easy, but do they know how)
  14. More detailed questions about the std. libraries (such as datetime/email/csv/zipfile/networking/optparse/unittest)
  15. Questions about testing (unittests/doctests)
  16. Questions about docstrings vs. comments, and the “Why” of them
  17. More detailed questions about regular expressions
  18. Questions about mutability
  19. Keyword/list parameters and unpacked keyword arguments
  20. Questions about popular 3rd-party toolkits (BeautifulSoup, pyparsing…mostly if they know about them and when to use them, not so much about implementation details)
  21. Questions about monkey-patching
  22. Questions about PDB
  23. Questions about properties vs. getters/setters
  24. Questions about classmethods
  25. Questions about scope/name-resolution
  26. Use of lambda
  27. Decorators added in which version?
  28. SQL-capable DB in which version?
  29. The difference between “class Foo” and “class Foo(object)”
  30. Questions from “import this” about pythonic code
  31. What do they know about various Python web frameworks (knowing a few names is usually good enough, though knowledge about the frameworks is a nice plus) such as Django, TurboGears, Zope, etc.
  32. What do they know about various Python GUI frameworks and the pros/cons of them (tkinter, wx, pykde, etc)
  33. Where do they go with Python related questions (c.l.p, google, google-groups, etc)
This entry was posted in Web dev. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments on Python interview questions and answers

  1. viral rami
    Posted 5/23/2008 at 1:20 am | Permalink

    26. Use of lambda

    It used to create small anonymous functions at run time.
    like e.g.

    def fun1(x):
    return x**2

    print fun1(2)

    it gives you answer 4

    the same thing can be done using
    sq=lambda x: x**2

    print sq(2)
    it gives the answer 4

  2. viral rami
    Posted 5/23/2008 at 1:30 am | Permalink

    1. Do they know a tuple/list/dict when they see it?

    Dictionaries are consist of pair of keys and {’key’:'value’}.


    keys are unique but values can be same.
    the main difference between list and tuple is
    you can change the list but you cant change the tuple.

    tuple can be used as keys in mapping where list is not.

  3. Anonymous
    Posted 5/28/2008 at 12:51 pm | Permalink

    2. When to use list vs. tuple vs. dictionary vs. set?
    List and Tuple are both ordered containers. If you want an ordered container of constant elements use tuple as tuples are immutable objects.
    When you need ordered container of things which will be manipulated, use lists.
    Dictionary is key, value pair container and hence is not ordered. Use it when you need fast access to elements, not in ordered fashion. Lists are indexed and index of the list can not be “string” e.g. list['myelement'] is not a valid statement in python.

Post a Comment

Your email is never published nor shared. Required fields are marked *