Python is an important programming language that any developer should know. Many programmers use this language to build websites, create learning algorithms, and perform other important tasks. But trying to learn Python can be intimidating, frustrating, and difficult, especially if you’re not sure how to approach it.
One of the things that I found most frustrating when I was learning Python was how generic all the learning resources were. I wanted to learn how to make websites using Python, but it seemed like every learning resource wanted me to spend two long, boring, months on Python syntax before I could even think about doing what interested me.
This mismatch made learning Python quite intimidating for me. I put it off for months. I got a couple of lessons into the Codecademy tutorials, then stopped. I looked at Python code, but it was foreign and confusing:
<span class="token keyword">from</span> django<span class="token punctuation">.</span>http <span class="token keyword">import</span> HttpResponse
<span class="token keyword">def</span> <span class="token function">index</span><span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">:</span>
<span class="token keyword">return</span> HttpResponse<span class="token punctuation">(</span><span class="token string">"Hello, world. You're at the polls index."</span><span class="token punctuation">)</span>
The code above is from the tutorial for Django, a popular Python website development framework.
Experienced programmers will often throw snippets like the above at you. “It’s easy!”, they’ll promise. But even a few seemingly simple lines of code can be incredibly confusing. For instance, why is one line indented? What’s
django.http? Why are some things in parentheses? Understanding how everything fits together when you don’t know much Python can be very hard.
The problem is that you need to understand the building blocks of the Python language to build anything interesting. The above code snippet creates a view, which is one of the key building blocks of a website using the popular MVC architecture. If you don’t know how to write the code to create a view, it isn’t really possible to make a dynamic website.
Most tutorials and Python courses assume that you need to learn all of Python syntax before you can start doing anything interesting. This is what leads to months spent just on syntax, when what you really want to be doing is analyzing data, or building a website, or creating an autonomous drone.
More often than not, spending all that time learning rote syntax leads to your motivation ebbing away, and to you just calling the whole thing off. I like to think of this as the “cliff of boring”. Many courses well tell you that you need to be able to climb the “cliff of boring” to make it to the “land of interesting stuff you work on” (better name pending).
But that’s not the only way to learn Python!
After facing the “cliff of boring” a few times and walking away, I found a process that worked better for me. Specifically, I found a way to blend learning the basics with building interesting things. In a way, I walked around the “cliff of boring” and headed straight for the top. I spent as little time as possible learning the basics, then immediately dove into creating things that interested me.
In this blog post, I’ll show you step by step how to replicate this process, regardless of why you want to learn Python. It all starts with finding your motivation
1. Figure Out What Motivates You to Learn Python
Before you start diving into learning Python online, it’s worth asking yourself why you want to learn it. This is because it’s going to be a long and sometimes painful journey. Without enough motivation, you probably won’t make it through. Make no mistake, even when you skip the “cliff of boring,” learning Python is still challenging.
Plus, motivation matters! I slept through high school and college programming classes when I had to memorize syntax and I wasn’t motivated. On the other hand, when I needed to use Python to build a website to automatically score essays, I stayed up nights studying to finish it.
In other words: it’s much easier to learn something when you have a reason to learn.
Figuring out what motivates you will help you figure out an end goal, and a path that gets you there without boredom. You don’t have to figure out an exact project, just a general area you’re interested in as you prepare to learn Python.
Pick an area you’re interested in, such as:
- Data science / Machine learning
- Mobile apps
- Hardware / Sensors / Robots
- Scripts to automate your work
Figure out one or two areas that interest you, and that you’re willing to stick with. You’ll be gearing your learning towards them, and eventually will be building projects in those areas, so choose things you’re actually interested in.
2. Learn the Basic Syntax
Unfortunately, this step can’t be skipped. You have to learn the very basics of Python syntax before you dive deeper into your chosen area. You want to spend as little time as possible on this, as it isn’t very motivating. I personally made it about 30% into the Codecademy Python tutorials, which was enough.
Here are some good resources to help you learn the basics:
- Codeacademy — does a good job of teaching basic syntax, and builds on itself well.
- Learn Python the Hard Way — a book that teaches Python concepts from the basics to more in-depth programs.
- Dataquest – Python Programming Fundamentals — I started Dataquest to make learning Python and data science easier. Dataquest teaches Python syntax in the context of learning data science. For example, you’ll learn about for loops while analyzing weather data. This course, and our intermediate Python course, are both free. We also have a lot of free Python tutorials.
- The Python Tutorial — the tutorial on the main Python site.
I can’t emphasize enough that you should only spend the minimum amount of time possible on basic syntax. The quicker you can get to working on projects, the faster you will learn. You can always refer back to the syntax when you get stuck later. You should ideally only spend a couple of weeks on this phase, and definitely no more than a month.
3. Make Structured Projects
Once you’ve learned the basic syntax, it’s possible to start making projects on your own. Projects are a great way to learn, because they let you apply your knowledge. Unless you apply your knowledge, it will be hard to retain it. Projects will push your capabilities, help you learn new things, and help you build a portfolio to show to potential employers.
However, very freeform projects at this point will be painful — you’ll get stuck a lot, and need to refer to documentation. Because of this, it’s usually better to make more structured projects until you feel comfortable enough to make projects completely on your own. Many learning resources offer structured projects, and these projects let you build interesting things in the areas you care about while still preventing you from getting stuck.
If you’re interested in learning Python for data science, each of our data science courses ends with a structured guided project that helps you apply your new skills creatively without totally dropping you into the deep end.
But you may be interested in Python because you want to make a game, or work in robotics, or do something else, so let’s take a look at some other great resources for finding structured projects you can dig into:
Data Science / Machine Learning
- Dataquest — As mentioned previously, our courses teach interactively by asking you to write real code to analyze real-world data, and each course ends with a guided project.
- Python for Data Analysis — A book written by the author of a major Python data analysis library, it’s a good introduction to analyzing data in Python, and it will help you learn some of the skills you’ll need for building data science projects.
- Scikit-learn documentation — Scikit-learn is the main Python machine learning library. It has some great documentation and tutorials you can work through to get a feel for how it’s used.
- CS109 — A Harvard class that teaches Python for data science. They have some of their projects and other materials online, and you can give them a try even if you’re not enrolled in the course.
Building Mobile Apps
- Kivy guide — Kivy is a tool that lets you make mobile apps with Python. They have a guide on how to get started.
- Flask tutorial — Flask is a popular web framework for Python. This is the introductory tutorial.
- Bottle tutorial — Bottle is another web framework for Python. This is how to get started with it.
- How To Tango With Django — A guide to using Django, a complex Python web framework.
- Codecademy — Has ineractive lessons that walk you through making a couple of simple games.
- Pygame tutorials — Pygame is a popular Python library for making games, and this is a list of tutorials for it.
- Making games with Pygame — A book that teaches you how to make games in Python.
- Invent your own computer games with Python — Another book that walks you through how to make several games using Python.
Hardware / Sensors / Robots
- Using Python with Arduino — Learn how to use Python to control sensors connected to an Arduino.
- Learning Python with Raspberry Pi — Build hardware projects using Python and a Raspberry Pi. The sky is really the limit here, but this page will give you some ideas for places to start.
- Learning Robotics using Python — A book that will help you learn how to build robots using Python.
- Raspberry Pi Cookbook — Another book that’s focused on helping your learn how to build robots using a Raspberry Pi and Python.
Scripts to Automate Your Work
- Automate the Boring Stuff with Python — A classic Python book that will help you learn how to automate everyday tasks using Python.
Once you’ve done a few structured projects in your own area, you should be able to move into working on your own totally unique projects. And because you’ll have been experimenting and working in your area of interest as you worked through those structured projects, you’ll probably have some cool ideas. But, before you dive completely into a passion project, it’s important to spend some time learning how to solve problems.
4. Work on Projects on Your Own
Once you’ve completed some structured projects, it’s time to work on your own unique projects. On your journey to learn Python, it’s hard to know how much you’ve really learned until you step out and try to build something on your own. You’ll still be consulting resources and learning new concepts as you work, but you’ll be working on whatever you want to work on.
Before you dive into working on your own projects, you should feel comfortable debugging errors and problems with your programs. Here are some resources that will help:
- StackOverflow — A community question and answer site where people discuss programming issues. You can find Python-specific questions here. You can ask your own questions if you need to, but often a search will reveal that someone else has already asked your question and gotten a good answer for it.
- Google — Believe it or not, this is the most commonly used tool of every experienced programmer. Very useful when trying to resolve errors. Here’s an example.
- Python’s official documentation — This is a good place to find reference material on Python.
Once you have a solid handle on debugging issues, you it’s time to dive into your own projects. Work on things that interest you. For example, I was interested in the idea of automated stock trading. That’s what motivated me, so I started working on tools to trade stocks automatically very soon after I learned the basics of Python programming.
Here are some tips for finding interesting projects:
- Extend the projects you were working on previously, and add more functionality.
- Go to Python meetups in your area, and find people who are working on interesting projects.
- Find open source packages to contribute to.
- See if any local nonprofits are looking for volunteer developers.
- Find projects other people have made, and see if you can extend or adapt them. Github is a good place to find these.
- Browse through other people’s blog posts to find interesting project ideas.
- Think of tools that would make your every day life easier, and build them.
Remember to start very small. It’s often useful to start with things that are very simple so you can gain confidence. It’s better to start a small project you actually finish than a huge project that never gets done.
It’s also useful to find other people to work with for more motivation.
If you really can’t think of any good project ideas, here are some in each area we’ve discussed:
Data Science / Machine Learning
- A map that visualizes election data by state.
- An algorithm that predicts the weather where you live.
- A tool that predicts the stock market.
- An algorithm that automatically summarizes news articles.
- An app to track how far you walk every day.
- An app that sends you weather notifications.
- A realtime location-based chat app.
- A site that helps you plan your weekly meals.
- A site that allows users to review video games.
- A note-taking platform.
- A location-based mobile game, where you capture territory.
- A game where players must write code to solve puzzles.
Hardware / Sensors / Robots
- Build sensors that monitor your house remotely (temperature, moisture, CO2 levels, etc).
- Build a smarter alarm clock.
- Create a self-driving robot that detects obstacles.
Scripts to Automate Your Work
- A script to automate data entry.
- A tool to scrape data from a website you frequent.
- A script that reminds you to stand up once every hour.
The first project I built on my own was adapting my automated essay scoring algorithm from R to Python. It didn’t end up looking pretty, but it gave me a sense of accomplishment, and started me on the road to building my skills.
Remeber, there aren’t really any wrong answers here. The key is just to pick something and do it. If you get too hung up on picking the perfect project, there’s a risk that you’ll never make one.
5. Keep Working on Progressively Harder Projects
Once you’ve finished the first one, keep increasing the difficulty and scope of your projects. If you’re completely comfortable with what you’re building, that means it’s time to try something harder. That could mean starting a new and more difficult project, adding complexity to your current project, or taking on an entirely different sort of challenge.
Here are some ideas for increasing the difficulty of your projects to ensure that you’re still progressing in your learning:
- Try teaching a novice how to build a project you made. Nothing forces you to really learn a subject quite like having to teach it
- Can you scale up your tool? Can it work with more data, or can it handle more traffic?
- Can you make your program run faster?
- Can you make your tool useful for more people?
- How would you commercialize what you’ve made?
Python is evolving all the time. There are only a few people who can legitimately claim to completely understand the language, and they created it. While you may quickly become comfortable with Python, even very experienced Python developers are still learning!
To progress quickly, you’ll need to be constantly learning and working on projects. If you do this right, you’ll find yourself looking back on your code from six months ago and thinking about how terrible it is. If you get to this point, you’re on the right track. And working only on things that interest you means that you’ll never get burned out or bored.
Python is a really fun and rewarding language to learn, and I think anyone can get to a high level of proficiency in it if they find the right motivation.