How To Learn Python: Programming by Hacking

How To Learn Python: Programming by Hacking

Python is exploding. And there’s a reason for that. It’s awesome! It seems everyone is learning it, teaching it, and hacking with it. Folks are even making python puppets and writing poetry in Python. While Python is easy to learn, it’s not necessarily easy to learn.

The following are the amazing resources I discovered and the hard-won lessons I learned on my adventure into programming.

Hack Through the Thicket

The best way to learn Python is with a project. Think of a (simple) problem you want to solve and start writing the program to get to the solution. I got sucked in with Twitter bots. I have a love/hate thing for Twitter. It’s like watching a river… a river full of garbage. But it’s a great place to learn Python. It’s so much fun to hack Twitter. It’s an incredible game of strategy: how much can you get away with before your account gets suspended? The best part is seeing immediate results. I was hooked when I wrote my first Twitter bot and saw the status update appear on my time line. “Hello, World!” on your Twitter account is much cooler than “Hello, World!” on your IDLE prompt. I’m currently writing a series of tutorials, intended for beginners, on how to hack the social media giant.

I understand that it t can be difficult for a beginner to think of a project when he or she doesn’t know what the language is capable of doing. Here’s a starter project that you, knowing nothing about Python at the outset, could easily accomplish in a day:

write a password generator.

You will utilize all the basics, and then some, in writing a program that produces the perfect password. It’s a very simple script, but you can geek-out and get crazy complex with it.

Hit the Books

Before you start or hack an existing project, you need to know the basics. There are a lot of Python books out there. While all of them will teach you what you need to know, some are better than others. These are my favorites, in order of accessibility:

1. Think Python

Downey gets you thinking like a programmer, which is more important than knowing or learning what every damn little thing does. Don’t fill your brain with with this stuff. That’s what Google is for.

Each chapter is loaded with exercises that ask you to use what you just learned to solve interesting, more or less practical, problems.

It’s free online.

2. python.org

Seriously, what better place to learn Python than from the source. The tutorials are actually good. It’s like they really want you to learn this stuff. It’s technically not a book, but what’s a book anymore?

3. Practical Programming

This book is very good at not only explaining how Python works, but how your computer works as well, and why it’s important to know as a programmer. The authors also run a MOOC on Coursera, but the book is so much better. Buy it on Amazon.

4. Real Python for the Web

The Real Python ebook package is amazing. You will go from noob to (almost) pro in an amazingly short amount of time. As the title suggests, it’s catered to those wanting to use Python for web development. If that’s you, throw down the money and get the bundle. It’s worth every penny.

The three gentlemen behind Real Python are approachable, knowledgeable, and witty. They sporadically post tutorials on their blog that range from beginner to advanced. Start with Lyricize: A Flask app to create lyrics using Markov chains. You will not only learn Python, you’ll be introduced to Flask and Markov chains while creating an app that is pretty cool.

5. Writing Idiomatic Python

Jeff Knupp knows his stuff. Much of what he covers in his book is advanced, but what better time to learn best practices than when you’re just starting out. The examples are easy to follow and understand and you will be setting yourself up for the future. His blog, Everything I Know About Python…, is specifically focused on web developers using Django or Flask, but he often writes about Python in general. Starting a Python Project the Right Way is an excellent introductory post.

Non-trivial Pursuit

StackExchange

Search for solutions to your problem. I don’t mean that in some metaphysical, philosophical way. I mean use a search engine. When you do, go to any Stack link first. There are a lot of content farms and dead end links out there. Your time is precious, especially when you’re learning Pythion in your free time. Go to Stack Exchange and you will find more than one answer and often an interesting debate about best practices.

Caveat: StackExcahnge can be frustrating for beginners because you have to earn reputation points. It makes sense, but it also makes it seem impenetrable. Pay your dues. It’s worth it. Also, it’s not just for programming. It’s massive.

GitHub

GitHub is a great resource for beginners because so many beginners create repositories for their early projects. These simple programs will demonstrate how to practically implement the concepts you are learning elsewhere. I found countless Twitter bot scripts on GitHub that I downloaded, hacked, and modified. When you define the problem you want to solve, search GitHub. Chances are someone else already wrote a solution. Clone or fork their repo and see how they solved your problem. Then proceed to tear it apart until it does exactly what you want. To get started with GitHub, create an account and check out their bootcamp.

If you take this approach you’ll begin to get comfortable with Git and Github. If you want to get serious, and you’re also a Linux enthusiast, you should learn both. A lot of Pythonistas swear by Mercurial and Bitbucket. I’ve only used them cursorily, so I can’t say anything one way or another. I started with Git. It works for me. I’ll stick with Git.

Lists & Newsletters

Tutor

Sign up for the Python Tutor list. I learned, and still learn, so much from it. But, be warned. The temperament of the list changes seasonally. It will swing from compassionate to cruel. When it turns sour, I usually unsubscribe for a few months, and I’ll resubsrcibe when I need help with a problem and stick with it until it gets bad.

Also, your Inbox will quickly fill up with mail from the list. You should read every email and follow the discussions as they evolve, even if you don’t grok.

Python Weekly

Sign up for Python Weekly. While most of it will be over your head in the beginning, you will receive an excellent recap of the goings-on in the Python community for the past seven days. Read through ALL of the headlines, but only click on those that you understand. After a few months, you’ll be opening every link and frustrated because you don’t have enough time to read and work through all of the posts.

The Stuff That’s Really Popular

You may have noticed that there are a number of obvious omissions from my lists above.

Everyone cites Zed Shaw’s Learn Python the Hard Way. It’s an excellent overview, but it’s not beginner-friendly. It was one of the first resources I encountered, but I could not stick with it. Now that I know the basics and I work back through Zed’s tutorials, I am able to see that it’s very good, but better suited for someone with programming experience making a transition to Python.

Some people love Codecademy, but I felt like they were holding my hand through the lessons and when they let go at the end, I was completely lost. Also, programming in a browser based shell doesn’t feel right. If you really want to learn Python, do it locally, with IDLE or your shell.

My last employer was a lynda.com subscriber, so I took advantage of the opportunity and, well, slept through the Python courses they offered. I find screencasts very hard to watch.

And then there’s the MOOCs: Coursera, edX, and Udacity. I’ve started and never finished courses in each. I find the pace of MOOCs frustratingly slow and unless you’re taking the course in real time, you can’t access the faculty or community for help when you hit a wall. If you have A LOT of time to kill, take these courses. Otherwise, carve your own path. You’ll learn much more and arrive at the same destination much faster.

Conclusion

I hope these suggestions are useful and helpful. At the end of the day, you are your best resource. You drive the learning, don’t let the learning drive you. In the spirit of the origins of the language, the best way to learn Python is with a sense of humor. Now get hacking!

Learn With Us

We want to take you on a journey through the other side of the creative process: making a living. Explore the necessary evils of business as we develop a creative media studio using free and open source software. Sign up for our New Moon newsletter delivered on, you guessed it, every New Moon.

Become a GNU/Linux Superuser!

Master the commands and structure of the fastest-growing computer operating system, Linux. Join super friends Adelie the penguin and Aramis the gnu on surreal adventures in the file tree. Learn the essential commands you need to take greater control of your computer in Superusers: The Legendary GNU/Linux Show.

Get It Now!
About the Author

How To Learn Python: Programming by Hacking was posted by on . Jared is one half of the creative force behind Dototot. In addition to writing scripts and tutorials, he draws and animates both the digital and the analog.

Discuss this article in the Comments below, or and it with your friends. Learn more about our creative process by subscribing to the New Moon Newsletter .

Recommended for you
Join the discussion

Subscribe to our New Moon Newsletter

How do you make money doing what you love? Sign up for monthly emails exploring the necessary evils of business as we develop a creative media studio using free and open source software.

The email entered is invalid
×