views:

2359

answers:

19

I have an interview for a Python job tomorrow through a personal connection. The thing is, I don't actually know Python although I've written a few programs and hacked around with Django and some other Python frameworks without really knowing what I was doing. An interview is a different matter. I'm planning on learning Python today even if I have to pull an all-nighter to do so. I just picked up a copy of "Python Pocket Reference" (2nd Edition) by Mark Lutz which covers Python Release 2.2. It's very condensed but that's kind of what I'm looking for because of this deadline.

  1. Will learning 2.2 be a big disadvantage?
  2. Am I using the "wrong" book?
  3. Are there better tutorials that cover the language rules concisely?

As for any skepticism about this approach, I got my last job in C++ after spending 3 days prior to the interview studying the language and did better on the technical test than many candidates who had actually worked with the language professionally. So my question is not really whether this can work - because if I do it right, I know it can - but whether I am using the best references for maximizing the next 24 hours.

+13  A: 

The fastest way is probably to read the tutorial on python.org, and writing a program or two on your own.

Lars Wirzenius
I agree this is how I learned python. It is a pretty simple language.
fuzzy-waffle
+15  A: 

Definitely don't use 2.2. 3.0 is out, and 2.2 is ancient by now. I would recommend 2.6 if you can swing it. As people are saying in the comments and other answers, 3.0 is too new, and 2.5 seems to be the current "standard". However, 2.6 is almost completely compatible with 2.5, and also teaches some good 3.0 compatibility habits, so if you're just starting now, I'd definitely shoot for 2.6.

There's a great book called "Beginning Python" by Magnus Lie Hetland. You can breeze through it quite fast if you already know how to code, and it covers things very well. Here's a link on amazon, although you'll probably want to find it at a local bookstore or something.

Luckily Python is a very clean orthogonal easy to use language. If all you need to learn is all of its syntax, you should be good.

Here's a list of features I would encourage you to be sure to learn:

  • List comprehensions (in all their incarnations)
  • For loop syntax
  • Tuple usage, including multiple assignment as in a, b = a+b, a
  • Lambda syntax
  • OOP basics (including the quirky "self" parameter for methods, and the importance of __init__, __str__, etc.)
  • First class functions (ie write sample programs that pass functions in to and out of other functions)
Benson
In practice, I think Python 2.5 is probably the most common version right now, but that's gradually switching over to 2.6. Some people still use 2.3. Python 3.0 isn't in widespread use yet at all (but it will be someday).
David Zaslavsky
+36  A: 

I would say the fastest way is to dive in.

Andrew Hare
Heh, I just clicked on this question to see if anyone had mentioned it yet. +1
Michael Myers
+1 Dive in to Python is a fantastic introduction. And it's free too so you can't go wrong.
Dave Webb
Beaten me by 5 minutes =)
Marcelo MD
I'm upvoting the chosen answer from 9 to 10 so that you get your Populist badge. Ha!
hughdbrown
fyi, updated link for version 3. http://diveintopython3.org
Keivan
+2  A: 

I recommend Dive into Python, a free web-based book with downloaded source examples.

Chase Seibert
+5  A: 

Here's a link to the official tutorial.

DNS
+6  A: 

I would recommend being honest, actually. But if you must, you can try the tutorial and try to implement some simple tasks. Also, I would study the standard modules. There is one for almost anything, so you don't need to reinvent the wheel unless asked to (which is a core point in Python's philosophy).

Two links, a complete book and a site with plenty of examples:

Mark Pilgrim's Dive into Python. and ActiveState, Python Recipes.

Marcelo MD
I don't think being honest about one's experience and learning as much Python as one can in 24 hours are mutually exclusive. I would do both.
Anders Sandvig
Certainly not, but I got the impression he was not planning to tell he learned Python just before arriving to the interview. Probably I was wrong."I don't know now, but I will try hard if given a chance" is always a good answer.
Marcelo MD
Yeah, "I don't have much experience with it, but I've worked with it a little and I feel comfortable enough with similar languages that I am confident I could get up to speed quickly" is honest enough, and if you happen to know enough to get through at least a few questions, that adds credibility.
Adam Jaskiewicz
+7  A: 

Don't learn 3.0. It's out, but it's a little too bleeding edge to be the thing to study for. (Either the company hasn't adopted it yet or the interviewer won't blame you for not having adopted it yet.) 2.2 is a major milestone for python, so if that's the print reference you have, go ahead and use it, unless some of the linked online tutorials work better. My recommendation would be to focus on what's available as of 2.6. A few things that come to mind:

  • function/method decorator syntax
  • class decorators
  • relative imports
  • improved try/except syntax (except ... as ... and unnested try/except/else/finally)

The first two are probably pretty good to know, and (more importantly) will double-check your understanding of some of the features new to 2.2. The last two might be somewhat minor, but my office is standardized around 2.4, and I sure as heck wish I had them.

Be good enough to let us know how you do!

David Berger
+3  A: 

Check out questions about python here. Here are few articles and videos that would help you learn things in couple hours

Below two videos by Alex Martelli will give you more information

Google I/O 2008 - Painless Python Part 1 of 2

Google I/O 2008 - Painless Python Part 2 of 2

Code Like a Pythonista

about python objects

yesraaj
+14  A: 
Gary Willoughby
Didn't know there was a third edition. Thanks. That's the same author who did the Pocket Reference I mentioned in my question.
ted
I'm not a fan of this book. I generally love O'Reily books, but I thought this one was a bit of a flop.
Benson
how can a book teach it to you in *one day*??
hasen j
I actually thought this was one of the best O'Reilly books I've ever read. Perhaps we just have different tastes, Benson.This book is how I learned Python, and I did skim through quite a few before I found one that I truly enjoyed.
Stefan Kendall
Like any cram session you did back in college, you can stuff your brain with enough facts to get by before they all drain back out again.
MattC
A: 

There's also a Python Quick Reference Card (http://www.limsi.fr/Individu/pointal/python/pqrc/) that's of some use, but too long at 18 pages, and somewhat out-of-date.

That, reading the first several chapters of your favorite tutorial, and writing sample code should do you well.

+2  A: 

One thing that will be hard to learn tonight is how to write pythonic code. Haven't figured out myself, what that means exactly, but with every line you read and write you get one step closer.

A lot of people fall into the trap of writing Java/C#/C/whatever with Python syntax. This is not something you are going to unlearn overnight.

Unless you have done some dynamically typed programming before, check out:

  • lists. Use them. Forget arrays
  • dictionaries. Use them all the time. They are your friend. Every problem gets easier with a dict or two :)
  • list comprehensions (just because they are fun - not necessary and not necessarily pythonic)
  • map(), reduce(), zip(), sum() etc. since they warp your brain

Classes aren't as important as Java might make you believe (Java just doesn't know any better).

Oh, and: Good luck with the interview! Hope you get the job! I'd envy you - coding Python for a living must rule!

Daren Thomas
+2  A: 

Again, do not learn 3.0. Go with 2.6. Read Dive Into Python, the Python tutorial, and Byte of Python. For more introductory reading/really light reading to get yourself started, I recommend Learn Python in 10 Minutes and A Beginner's Python Tutorial. Get cracking!

Andrew Szeto
A: 

Will learning 2.2 be a big disadvantage?

For your purposes, possibly not. I think “my Python's a bit rusty, I've not used the newer versions in anger yet” might be plausible! :-)

2.2 is a little way back, but a lot of the changes aren't that huge in practice. If you cover 2.2 from the book you'll want to supplement that with a few of the more important bits since then that you're more likely to meet:

  • generators/iterators
  • list comprehensions/generator expressions
  • new-style objects (you don't need to know this in detail, only that we now subclass ‘object’, and hold multiple inheritance in more suspicion and fear than we already did)
  • bool exists, we say True/False not 1/0 these days
  • ‘a if condition else b’ (like the traditional ?: ternary operator)

Here's a master list of stuffs:

http://docs.python.org/dev/whatsnew/index.html

Don't worry about 3.0 for interview purposes, it's not there yet.

bobince
A: 

Run python and just start playing around on the command line as you look through any of the tutorials people are mentioning. The great thing is that you can very quickly try out a lot of programming syntax right away and get immediate feedback. Warning, it's addictive!

David Plumpton
A: 
  1. Will learning 2.2 be a big disadvantage?

No. A surprisingly small amount has changed in Python, even since version 1 (pre-1.0 versions were missing some bigger things like user-definable classes, double " quotes and such..)

Of course much has improved since 2.2 - but pretty much everything you read in the book will be relevant to Python 2.5 or 2.6..

New best-practices, new modules and such may have been introduced, but for learning the language, documentation on 2.2 is fine.

Once you've gone through the book, as people have suggested Dive Into Python is a great next step, and explains how to do various things (like dealing with XML in Python, for example)

dbr
A: 

Mark Lutz, the author of Learning Python and Programming Python, posted a nice tutorial recently.

splicer
A: 

Starting from the other end, here are a few Python interview questions which quickly test your knowledge in various areas of the language.

MaxVT
+2  A: 

You might want to check out "How to Think Like a Computer Scientist: Learning with Python 2nd Edition"

Aurelio Tinio
A: 

O'Reilly Python Cookbook would be recommended.

http://oreilly.com/catalog/9780596007973/

Hope the interview went well.