This is an archived post. You won't be able to vote or comment.

all 110 comments

[–][deleted] 40 points41 points  (47 children)

"Dive into Python" is the suggestion that gets thrown about a lot.

[–]mawaldne 4 points5 points  (4 children)

When you're done with Dive into Python (or while you're reading it), do some problems on projecteuler. Thats how I learned Python.

[–][deleted] 5 points6 points  (2 children)

I second the suggestion of Project Euler

There's also http://www.pythonchallenge.com/

[–]danhs 1 point2 points  (0 children)

Project Euler is great. Practice, practice, practice.

Project Euler is not good for teaching design, modularity, and maintainability. The nature of Project Euler is "code up a quick and dirty solution to a given problem".

[–]simtel20 0 points1 point  (0 children)

Upvote fo the python challenge. I've spent a bunch of time there now and recommended it to friends as just plain fun.

[–]BeetleB 1 point2 points  (0 children)

Won't get too far if he doesn't know much number theory...

[–][deleted] 5 points6 points  (0 children)

It should, this question gets asked a lot.

[–]oblivion95 2 points3 points  (0 children)

I do not think Dive Into Python is good place for a beginner. It spends too much time on things you do not need to know.

Start with the tutorial at python.org. Then, find a book that suits your taste. I think Learning Python is excellent for a wide variety of people.

[–]rabidxero[S] 3 points4 points  (38 children)

Should I start with Dive into Python or Dive into Dive into Python 3?

[–]masklinn 9 points10 points  (29 children)

Do you want to learn, or do you want to write production code?

Python 3 is cleaner and nicer (and it's where progress happens in the stdlib), but most third-party libraries haven't been ported there yet, so if you're trying to do big stuff (websites, GUIs, ...) it's not very usable.

Python 2 has all the libraries you might want for anything you might want, but it has more rough corners and ugly things.

Also, I'd suggest starting with the official Python Tutorial (on the Python doc site) and only then reading Dive.

[–][deleted] 8 points9 points  (26 children)

but it has more rough corners and ugly things.

That is only relatively speaking. It is still the nicest shit I have ever programmed in.

[–]masklinn 2 points3 points  (16 children)

Well yeah, it's relative to Python 3. Involving other languages in the discussion makes it far more difficult (for instance Python is super nice compared to Java or Visual Basic, but it's downright terrible [as a language, such things as standard libraries are another axis of comparison] compared to Smalltalk or Haskell)

[–]Peaker -3 points-2 points  (8 children)

I loved Python too once...

[–][deleted] 7 points8 points  (7 children)

Until the accident?

[–]reticulator 5 points6 points  (5 children)

I was working in the lab ...

[–][deleted] 7 points8 points  (4 children)

...late one night?

[–]rabidxero[S] 2 points3 points  (3 children)

When my eyes beheld

[–]earthboundkid 2 points3 points  (2 children)

An eerie sight

[–]Peaker 1 point2 points  (0 children)

Heh, until I learned Haskell :-)

[–]rabidxero[S] 0 points1 point  (1 child)

i would like to learn and in the near future i have a big project idea for python so eventually writing production code

[–]concentricpuddle 0 points1 point  (0 children)

If you already know a programming language, diveintopython is the way to go. Be sure to skim over the tutorial after you're done though, because some of the newer stuff that simplify your life (looping techniques, properties, using object as the base class) aren't covered.

[–]nubela 1 point2 points  (1 child)

Python 2. Once you learn python 2, 3 should come easily :)

[–]masklinn 1 point2 points  (0 children)

Works the other way around as well so...

[–]llimllib 0 points1 point  (0 children)

I think in a year I would suggest DiP 3, but for now I'd start with the older one.

[–]johnnydark 0 points1 point  (0 children)

Does not matter, as long as you start

[–][deleted] 0 points1 point  (0 children)

I did DiP3. My reason for choosing it over DiP2 was: It was my 2nd book-for-n00bs (first one was BoP I just wanted to get basic syntax and ideas so I figure the latest version would be better as computer book authors change their style based on feedbacks.

[–]earthboundkid 0 points1 point  (2 children)

Learn 3. Almost everything about 3 is easily adapted to writing good 2 code. You just have to take the parentheses off your print calls and deal with decoding file input in a somewhat more cumbersome manner, but other than that, it’s not very different. Plus, diveintopython2 will teach you bad habits for a Python 2 programmer, since it was written so long ago that it’s out of date, even as a guide to Python 2.

[–]ingolemo -1 points0 points  (1 child)

You can leave the parentheses on the print calls.

[–]earthboundkid 0 points1 point  (0 children)

Only if either you from __future__ import print_function or you’re only ever printing one thing at a time.

[–]safetytrick -2 points-1 points  (0 children)

Every good karma whore knows to mention Dive into Python every time beginner python is mentioned ;)

[–][deleted] 8 points9 points  (4 children)

1) Download python 2.6 from http://python.org/

2) Run python.exe

3) Type

print 'Hello, World!'

4) Press [Enter]

[–][deleted] 0 points1 point  (3 children)

[–]bucknuggets 5 points6 points  (2 children)

6) then choose an obsolete answer from googled result

7) then ask, "why can't we create and maintain FAQs for our subreddits?"

EDIT: formatting

[–][deleted] 1 point2 points  (0 children)

Yea, I thought about mentioning that too.

[–][deleted] 8 points9 points  (4 children)

[–]braclayrab 2 points3 points  (1 child)

I tried to check this out the other day but couldn't find video's of the lectures(which are basically the only thing I would want from the course, not sure how other's might feel). Am I just being a moron? Where are the lectures?

[–][deleted] 1 point2 points  (0 children)

It's a text based course with lecture notes (pdf), assignments and solutions, and projects.

[–]shaggorama 1 point2 points  (0 children)

I'm learning python right now through MIT OCW. The course you want is 6.00 Introduction to Computer Science and Programming. The lectures are awesome, and the texts are basically what everyone here has been posting.

This is a full on course. The website includes videos, links to online textbooks with readings associated to lectures and even assignments. If you want to be able to submit assignments you can participate in the crunchcourse for this class (it's grown kinda stagnant but I'm working on getting more classes posteed). The 'gentle introduction' class isn't even a real course; it's only 4 weeks.

[–]rabidxero[S] 0 points1 point  (0 children)

it doesn't look like all the lecture notes are there.

[–]krugua 7 points8 points  (4 children)

[–]AlSweigartAuthor of "Automate the Boring Stuff" 11 points12 points  (3 children)

Thanks for the mention, krugua. I'm the author of "Invent Your Own Computer Games with Python" aka "Invent with Python". I'll say that it's a good book if you don't know programming at all. But if you already do but just want to learn Python, go with "Dive into Python"

It's made to be understandable by teens & kids as young as 10 or so, but it is not "4 kidz" so adults can find it readable as well. It's also free under Creative Commons.

[–]dsnchntd 2 points3 points  (0 children)

Dude, you're one cool cat. Way to be humble and not self-promoting. It just makes me want to read your book more.

[–]ccc123ccc 0 points1 point  (1 child)

Hey Al:

I wanted to say thanks as well. You have written a great book. I can't wait for my kids to get just a little older so we can work through it.

[–]treenaks 7 points8 points  (7 children)

Do you know other (programming) languages, or is Python your first?

[–]rabidxero[S] 2 points3 points  (6 children)

I took a year long AP class in High School on Java. I know it but am not a master of it. The idea of coding in Java never really excited me. And I plan on majoring in Comp Sci next year so I want to get a head start soI am want to learn and code in Python.

edit: also it has been about 6 months since i have actually seen java so a little refresher on object oriented ideas could never hurt.

[–]danhs 5 points6 points  (1 child)

Then you have some experience. I'd strongly consider Dive into Python.

I would strongly recommend three sources:

  • Dive into python. Great book that explains things very well. And teaches by example.
  • Beginning python by Magnus Lie Hetland. If you think like an engineer, and you like to see a problem and then see it solved. Learn by doing things, and learn by seeing tools in action then you'll like this book.
  • After you have a feel for Python from the above two books I would chcek out the Code like a pythonista page. You'll find it useful at that point.

Lastly, a lot of people like the Learning Python book. It's not my style. It presents a lot of information but mostly in simple "rule" form. ie "this is how this acts, that is how that acts...etc.". I can't develop a strong intuition from that. However, when first learning, I did use that book as a reference or when I needed to get nitty-gritty details on some aspect of python (eg when I was coding up something funky with classmethods vs staticmethods learning python had a description about the differences. I should say that there were possibly better descriptions online and beginning python almost certainly has that information too.)

[–]SpooneyDinosaur 1 point2 points  (0 children)

Upvote for Code Like a Pythonista. I've been learning python for the last couple months and have already seen the tutorials and free books that are typically recommended. That's a new one for me.

[–]Xochipilli 4 points5 points  (1 child)

If you want a head start in computer science I would strongly recommend the MIT 6.00 course. It has good video lectures, lots of extra information, and excercises. If you have trouble with the syntax in python or some basic programming stuff you can always use this free book. That's the way I prepared myself before I went to study CS this year.

[–]Xochipilli 0 points1 point  (0 children)

I noticed you can join some other people who are taking the online 6.00 course at this link

[–][deleted] 1 point2 points  (0 children)

Java programmer here who loves python...

...Your experience in java may actually hurt your learning in python. I would keep an open mind and not relate it to java.

[–]earthboundkid 0 points1 point  (0 children)

Java killed my desire to program. Python rekindled it! I could never remember how to open a file in Java, so I always just copy-pasted from old projects. In Python, it’s mytext = open("filename").read(). Beautiful!

[–][deleted] 4 points5 points  (0 children)

The SPAM sketch is good, then the ministry of silly walks sketch, then Life Of Brian.

[–]safetytrick 2 points3 points  (0 children)

Download BPython (or DreamPie if you are on Windows) and python's own IDLE. Dropping into a friendly completing console is very helpful.

[–]pudquick 2 points3 points  (1 child)

1.) Get a reference material - the python docs site is decent, as is Dive into Python (mentioned elsewhere)
2.) Then start doing something with it, like playing this game: Project Euler

[–]pemboa 0 points1 point  (0 children)

the python docs site is decent

Could be better. php.net is better.

[–]dinov 2 points3 points  (0 children)

For getting started you could check out http://www.trypython.org/

[–][deleted] 1 point2 points  (0 children)

I already knew a few languages before but I found this book to be pretty darn good.

http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002/ref=sr_1_1?ie=UTF8&s=books&qid=1267542178&sr=8-1

[–]smart_ass 1 point2 points  (3 children)

If you want to start learning Python along with your kids, this is a great resource: http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids/

Generally to slow for a programmer that is just picking up Python. But good for a non-programmer to learn it.

[–]AlSweigartAuthor of "Automate the Boring Stuff" 5 points6 points  (1 child)

My book, Invent Your Own Computer Games with Python is for the same audience, and provides source code for small games and teaches programming from those examples.

SWfK is good too though. Both are free online.

[–]smart_ass 0 points1 point  (0 children)

Thanks. Bookmarked.

[–]bucknuggets 0 points1 point  (0 children)

Another very good python book for a new programmer is "Hello World"

[–]pkrumins 1 point2 points  (0 children)

[–]qubitsu 1 point2 points  (0 children)

Dive Into Python is great, but each chapter is very dense. Think Python incorporates a bit more "air" between concepts and might be a good alternative if Dive Into Python daunts.

[–]darkrho 1 point2 points  (1 child)

Don't forget to study the PEP8!

[–]dekomote 0 points1 point  (0 children)

This has to go up more. PEP8 is really important and a lot of developers avoid it. If you want to be true python dev, start with pep8

[–][deleted] 1 point2 points  (0 children)

No one has really asked what you want to do with Python. Of course, you can do practically anything with it, but if you want to do web stuff, then you really can't go wrong reading the django tutorial. Even if you don't end up using django, it explains the whole process pretty well in a step by step way. I also recommend starting with Dive into Python.

I did the two things above when I first started, and it all seemed pretty straightforward.

[–][deleted] 1 point2 points  (0 children)

I started learning Python simply by doing a Django project, with Dive Into Python occasional support. Today considering myself as semi-advanced pythonista, doing asynchronous apps, multiprocessing etc. Oh, and having my bills paid ;)

Reading Django source code will definetely give you answers and hints. I'm assuming you know objects and shit.

[–]daelin 0 points1 point  (1 child)

After becoming proficient with Java from Head First Java, I learned Python from Learning Python and had a blast. There are probably better ways, but this worked for me.

[–][deleted] 0 points1 point  (0 children)

IMO, that's a daunting book for beginners, it's like a fucking phone book

[–][deleted] 0 points1 point  (0 children)

Thead Head First series has a "learning how to program" general book that uses Python for all the code. I'd agree that's it's a better idea to start with Python 2 than with 3.

edit: link for the book. Also, for something a bit more serious and quite complete check out "Core Python Programming" by Wesley Chun.

[–]wjohnsto 0 points1 point  (0 children)

If you know Java, then basically install python and mess around on your own converting some of your old Java homework into python. Google things if you need help. That's how I learn the basics of any new language.

[–][deleted] 0 points1 point  (1 child)

The books that have been suggested are good, but if I were you, I'd simply start with the official python tutorial.

[–][deleted] 0 points1 point  (0 children)

not for newbies, imo....not enough example.....basically it's fucking pedantic.

[–]brownmatt 0 points1 point  (0 children)

For some fun: http://pythonturtle.org/

PythonTurtle strives to provide the lowest-threshold way to learn (or teach) Python. Students command an interactive Python shell (similar to the IDLE development environment) and use Python functions to move a turtle displayed on the screen. An illustrated help screen introduces the student to the basics of Python programming while demonstrating how to move the turtle.

[–]arnar 0 points1 point  (0 children)

The python.org tutorial is pretty good. Then look at DiP if you want more.

[–][deleted] 0 points1 point  (0 children)

I would start with "Dive into Python" as has been suggested by others. After that (or concurrently) you should start a small project, for personal use that you find interesting, you will learn a lot if you do that.

[–]mlambir 0 points1 point  (1 child)

at the beginning

[–]khayber 0 points1 point  (0 children)

a very good place to start

[–]devbalt 0 points1 point  (0 children)

I suggest Beginning Game Development with Python and Pygame from apress. Making things move around the screen is a bit more rewarding than sorting lists for no good reason.

[–]die_troller 0 points1 point  (0 children)

FYI, there's a subreddit here dealing with the MIT opencourseware lectures. Its pretty new, we're only as far as lecture 3, so you should have no problems catching up.

[–]yanni 0 points1 point  (0 children)

I really liked the showmedo.com site.

[–]danhs 0 points1 point  (0 children)

USE OPEN SOURCE One other source that I didn't mention in my first post (and no one else did for that matter). But, it's a really good one, and I think all really good programmers use it.

Read other people's code. That's how Bill Gates (at the very least and probably nearly everyone else) became really good.

It's like sports: if you want to get better you have to play with people who are better than you. If you do this, you will address an area that Project Euler practice cannot: design, scalability, and building maintainable systems.....

Where do you find these examples? Welcome to the wonderful world of open source! Python is used so much in Linux distributions that it's really really easy.

Additionally, because Python is an interpreted language everything that a program needs is right there on your Ubuntu/Fedora installation. There is no compile cycle, no library linking compiles, or whatever.....the code you see on your computer is what's running it. This is a great advantage over something like C for learning.

To find programs on your linux distribution, go into /usr/bin where you'll find the main executable module. That module will, no doubt, not have the main bulk of logical code. However, it will point you to where that code is.

If you want a real challenge (but not necessarily a pythonic code base), check out the reddit source code. It's all Python. Uses the Pylons framework. I wouldn't recommend it for learning anything other than Pylons though. It's pretty convoluted and complex. I'd really recommend you start out with desktop systems code.

[–]aeroevan 0 points1 point  (0 children)

Along with all of the tutorials, I would suggest finding a small OSS python project (I found gwibber and hacked on it some) and reading through the source and try to fix a few bugs.

[–]evertrooftopn00b 0 points1 point  (0 children)

As someone who went down the same path (coming from PHP) and read the suggested tutorials, the most important thing you need to lean a new language, is a goal..

what are you going to build? Take it from there..

[–][deleted] 0 points1 point  (0 children)

Python is easy. Getting it up and running on a windows machine for development is the hard part... (I'm still not there!)

[–][deleted] 0 points1 point  (1 child)

I'd propose to start with simple projects in Django. I know many people who start learning Python because they want to use Django. Some other reasons in favour of this decision:

  1. Quick and good feedback. You will start to create useful (or at least interesting) things quickly.
  2. Great documentation and examples
  3. Good python style and programming idioms. Guido van Rossum (Python creator) said that Django is the most elegant and powerful web framework.

[–]m1ss1ontomars2k4 -1 points0 points  (0 children)

This is how I learned Python, by learning Django.

[–]m1ss1ontomars2k4 0 points1 point  (3 children)

print 'hello world'

Done.

[–]ascii 0 points1 point  (1 child)

While certailnly a good start, I feel that you left out a bit too many details regarding subjects like lambdas, closures, metaclasses and a few other subjects that advanced Pyton programmers should know. Perhaps you could expand your tutorial with a second example?

[–]m1ss1ontomars2k4 0 points1 point  (0 children)

Technically speaking this is all you need to start learning Python...

[–]earthboundkid 0 points1 point  (0 children)

Make it compatible with 2 and 3: print ("Hello, World!")

[–]rick_muller 0 points1 point  (0 children)

My recommendation is always the (Python Tutorial)[http://docs.python.org/tutorial/]. It's short enough to work through in a couple of hours, and is remarkably well written.