Want to know how to hire best Python developers?
Read our guide below
How to Hire a Python Developer: The Best Interview Questions
The number of Python developers in the world is between 2.1 and 4.5 million, according to very rough calculations.
Figures like these may lead you to think that hiring a Python Developer is easy, and it is — as long as your goal is to hire someone who can casually list Python among twenty-five other skills on their resume.
But if you’re looking for a true Python guru who has mastered every nuance of the language, you could be in for a shock.
We’ve collaborated with Business Analyst, a Python expert who works for one of our clients, to create this guide packed full of pro interviewing tips, questions, and sample coding tasks that will help you hire an A+ Python developer.
Starting Out
No matter how experienced the Python Developer you’re interviewing is, it never hurts to start with the basics. Check your candidate’s general understanding of programming concepts and common data structures by asking them to explain, for instance, what components a graph has, and what a binary tree is. If you’re happy with their answers, go ahead and ask them about the difference between a depth-first search and a breadth-first search.
Pay attention to the language the candidate uses. You’ll easily be able to tell a bright self-taught computer geek apart from an educated specialist with years of experience under their belt.
Once the candidate has tackled these topics, move on and ask them about the programming paradigms they’re familiar with. Invite them to talk about OOP and how its principles are implemented in Python. Make sure the candidate names all four principles — encapsulation, abstraction, inheritance, and polymorphism. If they can do that, you could pick one principle, say encapsulation, and ask them to talk about its peculiarities in Python, and the syntax of defining a private attribute or method.
While you’re on the subject, ask the Python engineer you’re interviewing how inheritance works in Python, and what abstract class, superclass, and static data are. If your candidate can’t provide a solid answer, they certainly don’t know enough to fill even a junior Python developer position.
Getting into the Weeds
Next, ask your candidate to list Python data types; dict, list, set, and tuple are just a few they should name. Don’t miss the chance to request an explanation of the difference between list and tuple.
A few other areas you might want to cover are Python’s generators and iterators, magic methods, GIL and multithreading, as well as the differences between Python 2 and 3.
One good way to establish whether the Python programmer in front of you is beyond junior level is to ask them what design patterns they know, and which of these are embedded in Python. If they name something simple, like Factory method or Singleton, ask them to explain what it’s all about. However, the one pattern that any good Python developer should definitely be familiar with is the Decorator, so make sure they can explain what it’s good for.
Testing the Framework Knowledge
If the position you’re trying to fill will include working with frameworks, it makes sense to check your candidate’s knowledge of this subject. To start off, simply ask what frameworks the candidate has used before. Nine out of ten Python developers, even the junior ones, will name Django, so go ahead and test their proficiency with this tool. Here are just a few questions you might want to ask a Django developer:
- What is MVC? How does it work in Django?
- What is your standard approach to working with databases?
- What are the differences between relational and non-relational databases?
- What is normalization and denormalization of the database structure?
- How do you tie a database transaction to the processing of an HTTP request? When would you use it?
- What data types do Django ORM methods return?
- Explain the Django ORM filter() function. What data type does the get() function return? What happens with the result of get() function if the database doesn’t contain the required record?
- What standard Django middleware classes do you know?
- How are HTTP requests and responses processed by middleware?
- What is Celery? What is a worker? What can be used as a broker?
Evaluating the Code Quality
You could start by asking the Python developer you’re interviewing to list the main PEP 8 conventions, or alternatively jump straight into viewing their code samples.
Taking a careful look at the candidate’s code is crucial as it accomplishes a number of things. One, it allows you to estimate how well they optimize their code. Two, it shows you whether they stick to PEP 8 and take code quality and readability seriously. Three, the way your candidate names objects and variables serves well to help you estimate the attitudes they have towards other team members who may also have to look at their code at some point, as well as their level of English, which is important if you’re hiring someone from a different country.
Sample Coding Tasks
No interview with a software engineer is complete without a few practical tasks, so invite the Python developer you’re interviewing to complete some for you. These are a few samples you may want to give a shot:
print list[10:]
This task helps determine the candidate’s understanding of data structures in Python.
dangerous = 2
c1 = C()
c2 = C()
print c1.dangerous
c1.dangerous = 3
print c1.dangerous
print c2.dangerous
del c1.dangerous
print c1.dangerous
C.dangerous = 3
print c2.dangerous
This one allows you to check the candidate’s understanding of objects and memory in Python.
print "%s/%s = %s" % (x, y, x/y)
def div2(x,y):
print "%s//%s = %s" % (x, y, x//y)
div1(5,2)
div1(5.,2)
div2(5,2)
div2(5.,2.)
This task allows you to see how well the candidate understands the peculiarities of mathematical operations in Python.
return [lambda x : i * x for i in range(4)]
print [m(2) for m in multipliers()]
This one shows whether the candidate knows how to use lambda functions.
smaller = x if x < y else y
print(smaller)
This one helps you check the candidate’s understanding of logical operators in Python.
def testgen(index):
weekdays = ['Sun', 'Mon',
'Tue', 'Wed',
'Thu', 'Fri',
'Sat']
yield weekdays[index]
yield weekdays[index+1]
day = testgen(0)
print next(day), next(day)
This task enables you to check the candidate’s understanding of how generators work.
x = 1
class Child1(Parent):
pass
class Child2(Parent):
pass
print Parent.x, Child1.x, Child2.x
Child1.x = 2
print Parent.x, Child1.x, Child2.x
Parent.x = 3
print Parent.x, Child1.x, Child2.x
The last task helps you test the candidate’s understanding of inheritance in Python.
Wrap Up
Bear in mind that the questions and sample tasks above are intended as advice, not a course of action. Not every Python programmer worth their salt will be able to answer all of them, nor does answering all of them guarantee a senior Python developer with outstanding expertise. You’ll definitely want to add a few other questions and consider setting tasks tailored for the project you’re hiring for.
We do hope, however, that you’ll be able to adjust our tips according to your needs and recruitment strategies, and hire just the right type of Python engineer for your business.