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.
This is not a discussion on how to hack or program with python, it’s a discussion on why I personally chose python as my first programming language. I’m not a developer, I’ve never written a program from source code to production. So when I started looking for a language to jump into I wanted something that could be used a stepping stone for lower level languages.
I chose python simply because I wanted to learn programming logic first, and syntax second. For those of you unfamiliar with those terms logic is how a program runs. It’s the decision making progress that determine what comes next and is derived of conditional statements such as if, if not, else, or’s etc. It’s the heart of any programming language and is usually the measure that separates good programmers from bad ones.
Syntax is how a program is written, it’s the way a language looks and reads/writes. Essentially syntax is programming grammar. Unlike grammar in the English language (Which I admit to being poor at) programs will NOT work unless you get the syntax exactly correct.
Logic is basically universal amongst all programs and to me is the difficult part while syntax can vary. This is exactly why I wanted to learn the logic first, once you understand how programming works you can kind of look at any program and pick it apart.
For example, in Java you would program:
public class HelloWorld
public static void main (String args)
But in python 3 you would type:
As you can see these two look very different, but they do the same thing. They print “Hello, world!” to standard out. As you can see Java has quite a bit going on compared to python but there are similarities behind each of the languages. The string “Hello, World!” that is printed to standard out is encased within quotes, and you call a function to print within each language. System.out.println() in Java and print() in python3. As you begin to learn more about functions, modules, libraries, variable declaration, objects, data structures and so on you will find that the similarities are even more apparent and your ability to decode them will expand. This is why many people can program or work in several languages.
As you saw from the above example python is a very compact and concise language. If you combine the large community, human readable syntax, powerful libraries and tutorial quantities its an easy choice to see why I started with python.
I did not learn from one resource and I bounced around between several sites and books. While I am not fluent in python I offer this bit of advice. Stick with it, programming is difficult. Its easily the most difficult thing I’ve ever had to learn in my life. I found that even though I struggle with learning concepts and logic after a while my mind adapts and and I begin to understand concepts that used to give me a lot of trouble. So stick with it.
If you’re interested in python I recommend learning from the following resources in the following order. 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 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.
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.
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 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
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.
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.
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.