share
Stack OverflowWhat did you use to teach yourself Python?
[+84] [34] Mez
[2008-09-21 19:40:59]
[ python ]
[ http://stackoverflow.com/questions/111857/what-did-you-use-to-teach-yourself-python ] [DELETED]

I'm an avid programmer, and I like to learn new languages. I normally teach them myself.

Python [1] isn't a "must-learn" language for me, but, as I work with Ubuntu [2], and a lot of their own code is now Python based, it'd be useful for me to learn, so that I can work with their code. I already know the basics of programming (and the advanced) and am versed in multiple programming Languages.

What are your suggestions for resources for learning Python, or how would you start working with Python to get yourself to a competent level with it?

[+86] [2008-09-21 19:42:38] Florian Bösch [ACCEPTED]

The best way to learn Python (or any programming language) is to pick something you want to do and start doing it in the language you want to learn.

Pick anything that interests you and is slightly more complex then a simple Hello World. IRC [1] bots are a good project, as are most small games like Snake [2], Tetris [3], etc.

For Python there exists a wealth of information both online and in dead tree form:

Books

Online

News

[1] http://en.wikipedia.org/wiki/Internet_Relay_Chat
[2] http://en.wikipedia.org/wiki/Snake_%28video_game%29
[3] http://en.wikipedia.org/wiki/Tetris
[4] http://oreilly.com/catalog/9780596513986/?CMP=AFC-ak_book&ATT=Learning+Python
[5] http://diveintopython3.ep.io/
[6] http://rads.stackoverflow.com/amzn/click/0596100469
[7] http://www.mindview.net/Books/TIPython
[8] http://docs.python.org/tut/
[9] http://docs.python.org/ref
[10] http://docs.python.org/
[11] http://www.python.org/doc/
[12] http://docs.python.org/lib
[13] http://rgruet.free.fr/PQR25/PQR2.5.html
[14] http://www.pythonware.com/daily/
[15] http://planet.python.org

I would add to this that many products (FOSS and commercial) are starting to use Python as their plug-in/scripting language of choice. If any of your tools use Python, that's the perfect way to learn. - James Schek
please add my book Core Python Programming to the dead trees section... it's been very well received for the past 11 years, and i am in the research phase for a 3rd edition! - wescpy
Perhaps it's misplaced for your list, but for myself to learn Python I took the llama book "Learning Perl", and did all the exercises in Python. Perl & Python are so similar that the exercises translated over very well, and the book is simply one of the best introductory programming texts I've ever seen. - Adam Parkin
a big +1 for 'dive into python'. really great intro into how to think pythonically. until i read that book i was just doing things in a C/Java style way, which doesn't really jive well with python in terms of readability or efficiency - Claudiu
1
[+36] [2008-09-21 21:14:21] Will Hartung

Learn it the way you learn any other language. Write a program in it. Any program. Some program that is interesting to YOU. Doesn't have to be a huge project, but it should be a couple hundred lines of code. Something more than "Hello World".

No reason to try and "learn Python" unless you have some specific goal. Rather take the goal, and apply Python to it.

What will you end up with? Most likely you will end up with "C in Python" or "Java in Python", or "FORTRAN in Python". That is, whatever language you're comfortable with now will influence how you write your early Python programs. "When I want to do X in language L, I do Q. How do I do Q in Python." Which completely side steps whether doing Q in Python is a good idea in the first place.

In the end you won't be creating "idiomatic" Python code, rather you'll create working Python code, using idioms and constructs that YOU are already comfortable with while at the same time learning the Python runtime, syntax, and other boiler plate that surrounds a language.

At the same time, inevitably, some Python idioms will "sneak" their way in to your code. It can't be helped. This casual exposure of system to your way of thinking is what makes it easier to apply, because you're applying the new constructs in a domain you're familiar with.

Now, once you've finished your first project, you can start your second. Only now the fundamentals of Python are much more clear to you. In the second project, the fundamentals become second nature and now you can try and stretch to create "idiomatic" Python. Basically, now you can write "Python in Python".

Inevitably, later, when you go back to some other language, you may start trying to write "Python in Java", or something similar. Some will take, some won't. Some will be very difficult and not worth the effort, other effects may surprise you.

But starting blind, with just a language book, for me, had never worked well. I know how to program, I just need to know how to program in the L language. Rather than starting from scratch, apply the knowledge you already have and you'll end up have quicker success in the short term, and a better foundation to really learn the language in the long term.


2
[+26] [2008-09-21 19:42:38] William Keller

The official tutorial [1] is great, as is Dive into Python [2]. However, I taught myself by writing an IRC bot.

[1] http://docs.python.org/tut/
[2] http://diveintopython3.ep.io/

I found DIP very overwhelming... and have also written an IRC Bot too! - Mez
Dive into Python is good for people who are already very familliar with programming. IRC bots are a great learning project, even though there are better libraries for "real" projects, writing an IRC bot covers so much ground that it helped me learn much of the standard library. - William Keller
3
[+13] [2008-09-21 19:46:40] Kaushik

Dive into Python as well. It's already present in Ubuntu 8.04 [1] (Hardy Heron) installations, so it's very convenient.

The Python Challenge [2] is a very pleasant way to get used to programming with Python. You also get to try some quirky puzzles, so it's quite enjoyable.

[1] http://en.wikipedia.org/wiki/List_of_Ubuntu_releases#Ubuntu_8.04_LTS_.28Hardy_Heron.29
[2] http://www.pythonchallenge.com/

The Python challenge is interesting! Very recommended! - Kenny M.
4
[+8] [2008-09-21 23:34:49] S.Lott

I learned Python by doing lots of small projects. See Building Skills in Python [1] for lots and lots of exercises.

[1] http://homepage.mac.com/s_lott/books/python.html

5
[+6] [2008-09-22 17:08:09] Ian Ozsvald

A lot of our users say that our ShowMeDo Python [1] tutorials are very helpful. There are 355 videos as I write this, with more open-source tutorials added each week.

All sorts of topics are covered, Python code is written and discussed whilst you watch leading you up to working examples.

Disclaimer - I'm a co-founder of ShowMeDo.

[1] http://showmedo.com/videos/python

6
[+5] [2008-09-22 09:40:20] e-satis

Well, there are great resources for advanced Python programming:

Here is a list of subjects you must understand if you want to master Python:

  • list comprehensions
  • iterators
  • generators
  • decorators

They are what make Python such a cool language (with the standard library of course, that I keep discovering everyday).

[1] http://en.wikipedia.org/wiki/Amazon.com

7
[+4] [2008-09-21 20:09:25] Metro

My daughter was a TA [1] at MIT [2] for a introduction computer class that used Python. I worked through their weekly programming assignments.

Here is a link that has the course's assignments for the semester before my daughter TA'd it.

6.00 Introduction to Computer Science and Programming [3]

[1] http://en.wikipedia.org/wiki/Teaching_assistant
[2] http://en.wikipedia.org/wiki/Massachusetts_Institute_of_Technology
[3] http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2007/Assignments/index.htm

(1) Are these available online though? - Martin Clarke
8
[+4] [2008-09-21 20:44:06] Kevin Little

Python In A Nutshell [1], by Alex Martelli. For an experienced programmer this is the best way, IMHO. Good, compact, to the point. In Martelli's case, pretty well written, too.

[1] http://rads.stackoverflow.com/amzn/click/0596100469

9
[+3] [2008-09-21 19:46:13] Sean

I agree with William Keller; use the tutorial to get your feet wet (it's short) and then read Dive Into Python or a Book, whichever works for you, as you begin your own project. At first, just to get the hang of the Pythonic style of doing things, check out all the great projects tagged with Python at Google OSS project hosting [1].

If you get stuck, you can normally get answers within seconds at the Python IRC channel [2] on freenode.

[1] http://code.google.com/hosting/search?q=label:Python
[2] http://www.python.org/community/irc/

10
[+3] [2008-09-22 06:58:48] brendonh

One of the standard recommendations over on Freenode's #python is:

Think Python: An Introduction to Software Design http://www.greenteapress.com/thinkpython/thinkpython.html

It's free, comprehensive, has lots of exercises, and tries to teach the Python mindset as well as the syntax.


11
[+3] [2008-10-08 20:43:51] Gregg Lind

Some free programming books in Python [1]

Two others:

NLTK Book [2] - Natural Language Processing using Python

Invent Your Own Computer Games With Python [3] - a kid-focused book on implementing Tic-tac-toe and other simple console based games. Very readable and easy even for an inexperienced programmer.

[1] http://www.freeprogrammingresources.com/pythonbook.html
[2] http://nltk.sourceforge.net/index.php/Documentation
[3] http://pythonbook.coffeeghost.net/book1/index.html

12
[+2] [2008-09-21 19:49:26] user18044

Lurk on the Usenet group for Python: Google groups [1]. Lots of interesting topics and good explanations.

Another nice resource is the Daily Python URL Daily Python URL [2]

[1] http://groups.google.com/group/comp.lang.python/topics
[2] http://www.pythonware.com/daily/

13
[+2] [2008-09-21 19:53:29] Michael Easter

As mentioned, find some interesting problems (small is better), and jump in.

As one resource (for any language), Project Euler [1] might inspire with some neat problems.

Another idea is to implement some of the classic data structures (e.g. Red-Black tree, or a priority queue).

I have come to love Python but won't deny that there were some frustrations at the start, as with any language. However, I do think that it is fairly easy to "get" the Python philosophy, because it is so intuitive and fluid. It may take time to become truly Pythonic but it doesn't take long to ask "which is closer to the Pythonic ideal: solution A or solution B?"

[1] http://projecteuler.net/

Honestly I found Project Euler to be far more of an exercise in mathematics than in programming. - Adam Parkin
14
[+2] [2008-09-21 19:57:23] tim.tadh

The book I used was Core Python Programming by Wesley J Chun. I believe it is a second edition now. I really liked it. I also have the Python Cookbook for a reference on how do specific tasks. The python library documentation is also really helpful. The best online community I found is the Python usenet group comp.lang.python.


UPDATE (Mar 2012): Part II of Core Python Programming (corepython.com) is now available in a 3rd edition: amzn.com/0132678209... however keep in mind that this book is for existing Python programmers who've learned the basics and want to move to the next level. The 2nd edition is still the my best book for programmers new to Python -- to extend its life in 2009, I added new appendices for 2.6 (also some 2.7 stuff) and 3.x. - wescpy
15
[+2] [2008-09-21 20:01:02] Jason Etheridge

I found the official tutorial to be sufficient. After that, I've only needed to refer to the library reference. Once the Pythonic way of doing things sinks in--and it really is intuitive, which is what makes the language such a joy to use--you find you don't need additional coaching.


16
[+2] [2008-09-21 20:26:55] postfuturist

I entered the PyWeek [1] competition. There are countless examples of working Python code for making games at pygame.org [2]. All the games from previous PyWeek entries are available with source code on the webpage, too. I learned a lot from looking at some of those entries. Having the time limitation encourages you to dig in, solve problems, and learn Python basics.

[1] http://pyweek.org/
[2] http://pygame.org/

17
[+2] [2008-09-22 01:54:40] Peter Turner

I don't think Python really requires reading anything at all, just think of something you want to do and do it in Python. When you hit a brick wall, search the documentation.

I'm not saying that the official documentation is helpful at all, but they help you piece together what you're trying to do.

Anyway, that's how I learned my share of Python, albeit a small one.


18
[+2] [2008-09-22 04:30:36] Crad

I've been going through this process recently and have found that beyond the following books, #python on irc.freenode.org to be very helpful.

  • Python - Essential Reference 3rd Edition by Beazley
  • Python in a Nutshell by Martelli

I use both books, while they're both similar, they touch on topics in slightly different ways.

I have found the best way to learn is to pick an application idea and bang my head against it with the various resources until I get it to where I want it. If it's something I plan on releasing with an open license, I've found asking #python on freenode to do code review as very helpful and enlightening. Good luck!


19
[+2] [2008-09-22 06:14:20] crystalattice

I decided I wanted to create an RPG based on an old pen and paper game, but I didn't like dealing with the idiosyncracies of C/C++. I had heard that Python was a good language so I decided to learn Python so I could write the game.

If you don't have a real need to learn a language, it will be difficult. Though it's old (Python 2.2), I would recommend getting a copy of Dietel & Dietel's "Python How to Program" book. It's structured like a college text book so it provides many different types of programs to write, from simple scripts to actual "real world" programs.


My usual way to get a basic understanding of a new language has been to implement the rules of tabletop RPGs. I've used that method Forth, Lisp, C++, Java, Python so far. 'Dive into Python' is also a good book for learning Python. - LAK
20
[+1] [2008-09-21 21:27:24] stalepretzel

http://www.projecteuler.net/
Project Euler is a great place to practice programming. It is a site full of math/programming problems, and Python is a great language to use to solve them. I got significantly better at python by using project euler.


I disagree that P.E. is a great place to practice programming. The challenge of the site is recognizing mathematical "tricks" rather than in learning the ins & outs of a language. If you're a "mathy" type person then it may be fun, but for the typical layman who cringes at the thought of doing tough math puzzles it's just an exercise in frustration. - Adam Parkin
21
[+1] [2010-11-05 13:08:30] subeen

I used the book 'Dive into Python' while learning, and I think it's a good one for experienced programmers. But recently I have found Google's Python Class [1] which should be very helpful for beginners.

[1] http://code.google.com/edu/languages/google-python-class/index.html

22
[0] [2008-09-22 05:59:38] Alvin Delagon

Dive into Python and by looking at other people's code.


23
[0] [2008-09-22 06:49:14] INS

The Python manual [1] is just as good as anything else.

[1] http://www.python.org/doc/current/

24
[0] [2008-09-22 09:44:49] Niklas Winde

I am currently implementing Conway's Game of Life [1]. It's pretty cool because it forces me to try some GUI packs for Python at the same time.

[1] http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

25
[0] [2008-09-22 09:49:35] Will Harris

I learnt the basics from Programming Python by Mark Lutz. Then I spent a few years programming Python in my day jobs.


26
[0] [2008-09-22 09:55:27] Vasil
  1. Start solving real problems.
  2. Read other people's code.

While i did read random chapters from a variety of books, most of what I learned was from the sourcecode of various frameworks (i.e. Django, Twisted). One of the greatest things about Python is that code is easy to digest 99% of the times.


27
[0] [2008-09-22 17:12:27] Joshua

Stanford School of Engineering has some free lectures that go over some Python: Introduction to Computer Science | Programming Paradigms [1]

Lectures 24+

[1] http://see.stanford.edu/see/lecturelist.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755ee

28
[0] [2008-09-22 22:34:20] Dan

Another vote for Dive Into Python here! What I most appreciate about it is that it goes beyond merely teaching you the syntax, to teaching you the basic "idioms" of Python programming so that you can write code in a style that is efficient and Pythonic.

After you've mastered that, O'Reilly's Programming Python is an excellent, excellent reference and guide to all the cool things you can do with Python, especially web and database programming.


29
[0] [2008-11-27 04:08:43] M. Utku ALTINKAYA

I have learnt Python while trying to do the right thing with other languages.


30
[0] [2008-11-27 04:25:12] humanlever

I've found A Byte of Python [1] by Swaroop C H, to be the most useful resource in laying out and explaining the fundamentals of Python in terms that mortals can understand.

[1] http://www.swaroopch.com/notes/Python_en:Table_of_Contents

Ditto :) I'd just added the same link, only to realize that this one was on page two of the comments. Very good book. - Mike Wagner
31
[0] [2008-11-27 05:24:07] dbr

No Internet connection, and the Python.org Tutorial.pdf [1].

[1] http://docs.python.org/download.html

32
[0] [2010-03-09 22:55:17] glasnt

I'm currently attempting to complete Project Euler [1] in Python. So far I've completed the first three, and learnt Python's methods of ranges, for statements, variable assignment, bool logic, output, loops, indentation nazi-ism, and commenting.

I come from a heavy Java/database background, and I'm sure I could do a lot of the Euler problems in Java, PL/SQL or Excel, given I know programming structures and problem solving, but I want to challenge myself with a new language.

It's like trying to converse to someone in French even though you know a lot of English, and they know English and French.

[1] http://en.wikipedia.org/wiki/Project_Euler

33
[-1] [2008-11-26 03:31:20] crystalattice

Well, to put in a blatant plug, I'm writing a Intro to Programming book [1] using Python. It's an ebook and will be free, if cost is a concern.

[1] http://python-ebook.blogspot.com

Just wanted to let everyone know that my book is completed and available in both print and electronic versions. Free copies are still available for download. - crystalattice
34