Interview questions banks will ask when you say you can code in Python
As an 'engineer' in an investment bank, I get to conduct a lot of interviews - especially with people who claim to be able to code in Python. They might be fellow coders, but they can also be traders who say they know how to code. After all, Python is a language with plenty of newcomers, and with plenty of people making big claims about their Python proficiency - sometimes incorrectly.
Before you step into a room claiming you know Python, you need to familiarize yourself with the following stumbling blocks from a typical Python job interview. I've tripped up a lot of interviewees with these myself; this is my guide on how to remain standing.
Why is Python called a dynamically typed programming language?
This is my opener. If you can code in Python, you'll know the answer. Unlike a statically typed language, that requires you to declare the data types of your variables before you use them, a dynamically typed language checks the type of the variable during run-time. Assignment statements bind variables to objects, and it's possible to execute a program so that different variables are bound to different types of object.
What’s a list comprehension?
On the face of it this looks like an easy question to answer. Of course, it’s a shorthand way of creating a new list. For example, adding two to every number in an existing list:
new_list = [ x + 2 for x in numbers ]
But then the interviewer might delve a bit deeper and ask something like “so it’s the equivalent of a for-loop appending to list?”. A naive candidate would say “yes”, but that’s not true - usually. List comprehensions are more efficient than loops where the list in the loop is created with no elements initialised. In the list comprehension, we know what the size of the result is going to be, therefore Python can allocate the memory upfront, which is much more efficient than dynamically adding to a list.
The interviewer might get even more evil by asking whether defining lambda expressions directly in a list comprehension is a good idea. It is not. So, a simple question can quickly get bogged down in minutiae about things you don’t consciously think about day-to-day, even as an experienced developer. This is a real challenge as a new coder – it’s natural for interviewers to see how deep a candidate’s knowledge goes and my advice is to be upfront and not get flustered when you don’t know something. That way the interview can quickly move on to something you might know.
Why do people say that python is single threaded?
Here the interviewer wants to know what your understanding of the global interpreter lock is. Python has thread packages, but in some versions of Python the global interpreter lock ensures that at any given point in time only one thread can execute (it holds the lock). It might look like things are running in parallel but they’re really not. It increases the speed of single threaded applications and makes integration of C libraries which aren’t thread-safe easy. So far so good.
The interviewer then might ask, “Can we run anything in parallel in Python?”. This is when they want you to talk about processes versus threads, and the fact that Python has a good multiprocessing library. We could also farm out requests to a compute pool or a job queue like Celery. The global interpreter lock also doesn’t stop threads processing many input/output requests at the same time – the lock is shared whilst threads are waiting for the requests to finish and this is particularly effective on versions of Python after 3.2.
What are you preferred Python libraries?
Here, I'm looking for people to talk honestly about their experiences with Python, but if they've used one of the libraries popular in banking it will help. I'd like to know that you're at least aware of things like NumPy and Pandas.
Don't lose your head
As a new coder, in a trivia question style interview it’s very likely that you won’t know everything that will be asked; the trick is to deal with that.
It goes without saying that you should know the major syntactic elements of Python – things like generators, the differences between list and tuple, lambda expressions, filtering iterables and so on. It’s very helpful to know how the core data structures work. For example, you’ll often be asked how a dictionary works under the hood. You should also have opinions on the type system and interpreted nature of the language in comparison to a statically typed and compiled language (it’s a question of trade-offs). As in any other language you should make sure to have practiced algorithm and data structure questions on a platform like HackerRank and Leetcode. You can also be presented with code on paper and it’s useful to practice dry running code in your head as well.
James Jones is the pseudonym of a technologist in a U.S. investment bank.
Click here to create a profile on eFinancialCareers. Make yourself visible to recruiters hiring Python developers for in finance.
Have a confidential story, tip, or comment you’d like to share? Contact: firstname.lastname@example.org in the first instance. Whatsapp/Signal/Telegram also available (Telegram: @SarahButcher)
Bear with us if you leave a comment at the bottom of this article: all our comments are moderated by human beings. Sometimes these humans might be asleep, or away from their desks, so it may take a while for your comment to appear. Eventually it will – unless it’s offensive or libelous (in which case it won’t.)