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:
- Do they know a tuple/list/dict when they see it?
- When to use list vs. tuple vs. dictionary vs. set?
- Can they use list comprehensions (and know when not to abuse them?)
- Can they use tuple unpacking for assignment?
- String building. Do they use “+=” or do they build a list and use .join() to recombine them efficiently?
- Truth-value testing questions and observations (do they write “if x == True” or do they just write “if x”)?
- Basic file-processing (iterating over a file’s lines)
- Basic understanding of exception handling
- 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
- Questions about iterators/generators
- Questions about map/reduce/sum/etc family of functions
- Questions about “special” methods (__foo__)
- Can they manipulate functions as first-class objects (Python makes it easy, but do they know how)
- More detailed questions about the std. libraries (such as datetime/email/csv/zipfile/networking/optparse/unittest)
- Questions about testing (unittests/doctests)
- Questions about docstrings vs. comments, and the “Why” of them
- More detailed questions about regular expressions
- Questions about mutability
- Keyword/list parameters and unpacked keyword arguments
- 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)
- Questions about monkey-patching
- Questions about PDB
- Questions about properties vs. getters/setters
- Questions about classmethods
- Questions about scope/name-resolution
- Use of lambda
- Decorators added in which version?
- SQL-capable DB in which version?
- The difference between “class Foo” and “class Foo(object)”
- Questions from “import this” about pythonic code
- 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.
- What do they know about various Python GUI frameworks and the pros/cons of them (tkinter, wx, pykde, etc)
- Where do they go with Python related questions (c.l.p, google, google-groups, etc)

3 Comments on Python interview questions and answers
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
1. Do they know a tuple/list/dict when they see it?
Dictionaries are consist of pair of keys and values.like {’key’:'value’}.
book={’cprog’:'1024′,’c++’:'4512′}
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.
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.