Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am going to interview within two weeks for an internship that would involve Python programming.

Can anyone suggest what possible areas should I polish? I am looking for commonly asked stuff in interviews for Python openings. Apart from the fact that I have already been doing the language for over a year now, I fail to perceive what they can ask me.

Like for a C or C++ interview, there are lots of questions ranging from reversing of strings to building linked lists, but for a Python interview, I am clueless.

Personal experiences and/ or suggestions are welcomed.

share

locked by Thomas Owens Oct 16 '13 at 17:48

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as not constructive by gnat, GlenH7, Glenn Nelson, MichaelT, Eric King Feb 7 '13 at 14:53

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

    
If it's an internship, and you've been programming in Python for a year already, I think you're going to be all right. Tha said, I think the general nature of the questions for Python will be the same as the ones you mentioned for c++. –  Robert Harvey Nov 27 '10 at 18:05
    
Robert, programming without any supervision and guidance is what bothers me. Maybe I lack in some areas. –  Andy Nov 27 '10 at 18:07
1  
If it's an internship, why won't you have guidance? That's the very definition of an internship. That said, the interns where I work don't get programming classes, but they do get clear work instructions and expectations. As an intern, they should expect that you will learn on the job, and that the work will take a little longer than it might if someone with experience does it. –  Robert Harvey Nov 27 '10 at 18:49
    
You're making a common mistake that many people make coming out of school - an interview is not a test, it's more like going on a first date. A good interviewer won't bust your balls trying to find out if you know dark corners of a language but rather try to establish, in general, if you actually know it. A good interviewer will focus on general programming knowledge, problem solving skills, interpersonal skills & experience. If somebody starts asking the specifics of how Python interns strings, it means they're lost and don't know how to interview. –  Sean McSomething Feb 7 '13 at 18:09
comments disabled on deleted / locked posts

8 Answers

Here are some easy ones:

  1. What are Python decorators and how would you use them?
  2. How do you debug your Python code?
  3. How would you setup many projects where each one uses different versions of Python and third party libraries?
  4. Do you follow PEP8 while writing your code?
share
add comment

How about something involving Python list comprehensions? To me, those were one of the big selling points over C++, after I read about them in Dive into Python.

"Write a list comprehension that builds a list of the even numbers from 1 to 10 (inclusive)".
Where the answer is anything like this (note the range values avoid a fencepost error):

foo = [x for x in range(1, 11) if (x % 2) == 0]
print foo
[2, 4, 6, 8, 10]

For that matter, if you understand all the concepts listed in Dive into Python, that should cover most of the important features.

share
13  
This is unpythonic. In Python 2.x, you just do range(2,11,2) and in Python 3.x, list(range(2,11,2)). –  Chinmay Kanchi Nov 28 '10 at 15:13
    
@Cyclops, sounds like you need to interview for your own job at INNOTECH. –  Job Aug 5 '11 at 1:56
5  
@Chinmay Kanchi While I don't think it would be a good interview question, most introductions to advanced features do the most simple things they can (as not to confuse the reader). While there is a more simple solution for this specific problem, the point was not to answer this specific problem. The point was to use a list comprehension (which are very effective and a notable way to optimize things in Python). –  jsternberg Aug 5 '11 at 4:18
add comment

Is Python pass by reference or pass by value is also a very good question.

share
1  
A great follow up question would be to ask how they can show it and why it matters –  mcotton Nov 29 '10 at 5:05
    
@Ismail - Sorry, but why is this a good question? –  Theodor Apr 17 '11 at 18:19
7  
@Cervo: If I understand correctly, Python is pass-by-value just as how C#, Java, Scheme, etc. are pass-by-value... the only pass-by-reference language I've seen is VB6, where everything is pass-by-reference unless specified otherwise. The fact that you can mutate the objects doesn't make it pass-by-reference in any way, and the fact that you can have immutable objects doesn't imply that they're being passed by value either... so saying "the answer is neither" is completely wrong. I feel very sorry for the candidate whose interviewer believes the answer to be "neither"... –  Mehrdad Aug 5 '11 at 4:12
1  
@Cervo: FYI, even the 100+ voted answer in your link counters your argument: it says clearly that "Parameters are passed by value." –  Mehrdad Aug 5 '11 at 4:17
11  
I believe the correct answer is: "Parameters are references that are passed by value." –  user16764 Aug 5 '11 at 7:34
show 3 more comments

Questions I've been asked:

  • Describe two methods of meta-programming in Python.
  • What is the GIL?
  • Why is the GIL important?
  • Why is there an alternative implementation of Python called Unladen Swallow?
  • Django, Pylons, or Zope? Defend your position.
share
    
+1 for GIL. Apparently a favorite question to ask. –  Demian Brecht Dec 12 '11 at 23:19
add comment

I have no such experiences, but here are some guesses:

  1. (Im)mutability
  2. First class functions/classes
  3. Closures

That's some stuff that python programmer should know, otherwise you may as well hire C programmer for the position.

share
    
+1 for c programmer –  Zagorulkin Dmitry Feb 7 '13 at 10:33
add comment

I would go along the list in this answer. Try to refresh what you know following that list as far as you can. Don't worry if you cannot make it until the very end.

share
add comment

Besides other links people have provided. I also recommend Hidden Features of Python. Just in case they throw some tricky questions at you.

share
add comment

What is your sense, will they be trying to test whether you know Python, see whether you can get things done in Python, or test whether you can program (in Python)?

Those are very different things.

If they want you to show that you know Python, they may force you to do things like create a generator, then do it without using yield. Explain how classes work. Explain the C3 method resolution order. And so on.

If they want you to show you can get things done in Python, you'll need to be competent with the basic data structures, and have a list of libraries that you'd go to for different kinds of tasks. So you need to be comfortable with dictionaries, sets, arrays. Likewise you need to know about things like BeautifulSoup for parsing HTML, be able to talk about a framework that could be used for web development, etc. You don't necessarily need to know how to use those things well, but you should know where to go, how to figure out more, and be able to actually use them once the interviewer has given you things that are documented.

If they want you to show that you can program (in Python), you'll need to know the basic data structures, and know your algorithms. This is much closer to the C/C++ questions that you'd be asked, except that you'll be expected to use native data structures where it makes your life easy.

To be safe you should prepare to some extent for all three. For instance read through http://docs.python.org/tutorial/ and make some notes to yourself. Hopefully you already know how to program. And then try some random tasks, and force yourself to use libraries that you may have missed. So, for instance, read some CSV, extract information programmatically out of a web page, build a small website with a framework, etc.

share
add comment