Python is an important programming language to know — it's widely-used in fields like data science, web development, software engineering, game development, automation. But what's the best way to learn Python? That can be difficult and painful to figure out. I know that from experience.
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:
from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls index.")
The above code 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 are some lines 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 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.
This is what 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”. 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).
After facing the “cliff of boring” a few times and walking away, I found a process that worked better for me. In fact, I think this is the best way to learn Python.
What worked was blending learning the basics with building interesting things. 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 walk you through step by step how to replicate this process, regardless of why you want to learn Python.
Step 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. For example, 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 to finish it.
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
- Data processing and analysis
- Hardware / Sensors / Robots
- Scripts to automate your work
Yes, you can make robots using Python! From the Raspberry Pi Cookbook.
Figure out one or two areas that interest you, and you’re willing to stick with. You’ll be gearing your learning towards them, and eventually will be building projects in them.
Step 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 the minimum amount of time on this, as it isn’t very motivating.
Here are some good resources to help you learn the basics:
- Learn Python the Hard Way — a book that teaches Python concepts from the basics to more in-depth programs.
- Dataquest – Python for Data Science Fundamentals Course — 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.
- 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.
Also, a quick note: learn Python 3, not Python 2. Unfortunately a lot of "learn Python" resources online still teach Python 2, but you should definitely learn Python 3. Python 2 is no longer supported, so bugs and security holes will not be fixed!
Step 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.
Let’s look at some good resources for structured projects in each area:
Data science / Machine learning
- Dataquest — Teaches you Python and data science interactively. You analyze a series of interesting datasets ranging from CIA documents to NBA player stats. You eventually build complex algorithms, including neural networks and decision trees.
- Python for Data Analysis — written by the author of a major Python data analysis library, it’s a good introduction to analyzing data in Python.
- Scikit-learn documentation — Scikit-learn is the main Python machine learning library. It has some great documentation and tutorials.
- CS109 — this is a Harvard class that teaches Python for data science. They have some of their projects and other materials online.
- 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 — walks 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 — a book that walks you through how to make several games using Python.
An example of a game you can make with Pygame. This is Barbie Seahorse Adventures 1.0, by Phil Hassey.
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.
- Learning Robotics using Python — learn how to build robots using Python.
- Raspberry Pi Cookbook — learn how to build robots using the Raspberry Pi and Python.
Scripts to Automate Your Work
- Automate the boring stuff with Python — learn how to automate day-to-day 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 projects. But, before you do, it’s important to spend some time learning how to solve problems.
Step 4: Work on Python Projects on Your Own
Once you’ve completed some structured projects, it’s time to work on projects on your own to continue to learn Python better. You’ll still be consulting resources and learning concepts, but you’ll be working on what 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 you should be familiar with:
- StackOverflow — a community question and answer site where people discuss programming issues. You can find Python-specific questions here.
- Google — the most commonly used tool of every experienced programmer. Very useful when trying to resolve errors. Here’s an example.
- Python documentation — a good place to find reference material on Python.
Once you have a solid handle on debugging issues, you can start working on your own projects. You should work on things that interest you. For example, I worked on tools to trade stocks automatically very soon after I learned programming.
Here are some tips for finding interesting projects:
- Extend the projects you were working on previously, and add more functionality.
- Check out our list of Python projects for beginners.
- 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 that you finish that a huge project that never gets done. At Dataquest, we have guided projects that give you small data science related tasks that you can build on.
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 Project Ideas
- A map that visualizes election polling 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.
You could make a more interactive version of this map. From RealClearPolitics.
Mobile App Project Ideas
- An app to track how far you walk every day.
- An app that sends you weather notifications.
- A realtime location-based chat.
Website Project Ideas
- A site that helps you plan your weekly meals.
- A site that allows users to review video games.
- A notetaking platform.
Python Game Project Ideas
- A location-based mobile game, where you capture territory.
- A game where you program to solve puzzles.
Hardware / Sensors / Robots Project Ideas
- Sensors that monitor your home temperature and let you monitor your house remotely.
- A smarter alarm clock.
- A self-driving robot that detects obstacles.
Work Automation Project Ideas
- A script to automate data entry.
- A tool to scrape data from the web.
My first project 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.
The key is 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.
Step 5: Keep working on harder projects
Keep increasing the difficulty and scope of your projects. If you’re completely comfortable with what you’re building, it means it’s time to try something harder.
Here are some ideas for when that time comes:
- Try teaching a novice how to build a project you made.
- 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?
At the end of the day, 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.
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 6 months ago and thinking about how terrible it is. If you get to this point, you’re on the right track. 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.
I hope this guide has been useful on your journey. If you have any other resources to suggest, please let us know!
Find out more about how you can learn Python and add this skill to your portfolio by visiting Dataquest.
Common Python Questions:
Is it hard to learn Python?
Learning Python can certainly be challenging, and you're likely to have frustrating moments. Staying motivated to keep learning is one of the biggest challenges.
However, if you take the step-by-step approach I've outlined here, you should find that it's easy to power through frustrating moments, because you'll be working on projects that genuinely interest you.
Can you learn Python for free?
There are lots of free Python learning resources out there — just here at Dataquest, we have dozens of free Python tutorials and our interactive data science learning platform, which teaches Python, is free to sign up for and includes many free missions. The internet is full of free Python learning resources!
The downside to learning for free is that to learn what you want, you'll probably need to patch together a bunch of different free resources. You'll spend extra time researching what you need to learn next, and then finding free resources that teach it. Platforms that cost money may offer better teaching methods (like the interactive, in-browser coding Dataquest offers), and they also save you the time of having to find and build your own curriculum.
Can you learn Python from scratch (with no coding experience)?
Yes. At Dataquest, we've had many learners start with no coding experience and go on to get jobs as data analysts, data scientists, and data engineers. Python is a great language for programming beginners to learn, and you don't need any prior experience with code to pick it up.
How long does it take to learn Python?
Learning a programming language is a bit like learning a spoken language — you're never really done, because programming languages evolve and there's always more to learn! However, you can get to a point of being able to write simple-but-functional Python code pretty quickly.
How long it takes to get to job-ready depends on your goals, the job you're looking for, and how much time you can dedicate to study. But for some context, Dataquest learners we surveyed in 2020 reported reaching their learning goals in less than a year — many in less than six months — with less than ten hours of study per week.
Do you need a Python certification to find work?
We've written about Python certificates in depth, but the short answer is: probably not. Different companies and industries have different standards, but in data science, certificates don't carry much weight. Employers care about the skills you have — being able to show them a GitHub full of great Python code is much more important than being able to show them a certificate.
Should you learn Python 2 or 3?
We've written about Python 2 or Python 3 as well, but the short answer is this: leanr Python 3. A few years ago, this was still a topic of debate, and some extreme predictions even claimed that Python 3 would "kill Python." That hasn't happened, and today, Python 3 is everywhere.
Is Python a good language to learn in 2020?
Yes. Python is a popular and flexible language that's used professionally in a wide variety of contexts. We teach Python for data science and machine learning, for example, but if you wanted to apply your Python skills in another area, Python is used in finance, web development, software engineering, game development, etc.
Moreover, Python data skills can be really useful even if you have no aspiration to become a full-time data scientist or programming. Having some data analysis skills with Python can be useful for a wide variety of jobs — if you work with spreadsheets, chances are there are things you could be doing faster and better with a little Python.