default author profile
Alys Brooks

The Basics of Learning Python

So you want to learn Python. Great choice! Even if you have a book or course in mind to help get you started, you may be wondering about the path ahead. Start with learning the ins-and-outs - the basics - of Python. Be ready to get stuck, and don’t be afraid to ask for help. Python is challenging, but like most languages, rewards hard work.

Once you’ve got the basics, you’ll be able to focus on the area or project for which you want to use Python. Here’s some expert advice on how to learn Python, from the very basics to the intermediate stage and beyond.

While this guide is Python-focused, a similar approach works for any programming language.

Python programming language is not quite as old as some other languages, but has been around for a long time. It was first released in 1991. It’s changed considerably over the years, but Python is still used for the same things it was at the beginning - one of the reasons why it has has become popular in recent years. Python is a production-based language, and can be used for just about anything, making it incredibly versatile. With Python, there really are no limits.

Four students, four approaches to learning Python

In this article, we’ll follow four hypothetical students with different backgrounds and goals to give you a sense of what learning a programming language is like. Here’s what their goals are:

Katarina - Data science

Katarina is a graduate student who wants to become a data scientist. She’s written code before, and Python is a new language she thinks will be perfect for analyzing data about health outcomes.

Devonte - IT Automation

Devonte is a network administrator who wants to do more automation. The only other administrator in his company is retiring, making him the most senior technical employee. He hopes 2020 means the start of a new era of automation.

Tim - Web development

Tim is a dad who volunteers at a local animal shelter. The shelter struggles to get the word out about pets who need homes. He wants to make a web application that automatically shares pictures of pets posted on the shelter’s website to social media.

Priya - Digital art

Priya is a seventh grader who is curious about computers, enjoys art, and wants to combine the two to try something new.

Walk before you run

Regardless of your plans with Python, you should focus on learning the basics of the language first, rather than learning specifics for your actual project.

For example, if you want to focus on data science, it’s appealing to leap right into Pandas, perhaps the #1 library for manipulating data in Python. Tackling Pandas right off the bat probably seems like a shortcut, and maybe even more interesting than basic Python commands, but it will likely take much longer and be more frustrating.

Why? Particularly if you’re new to programming, just learning a language requires you to learn multiple things at once. You must learn both the concepts of the language (for example, using a for loop to repeatedly run code) and its syntax, or details of how it’s written (like putting a colon at the end of the line introducing a for loop). If you attempt to learn the details of something more in-depth and complicated, like accessing computers, analyzing data, or handling web app visitors at the same time, you’ll probably find it’s a bit too much to wrap your head around. Many students experience the same.

It’s also harder to ask for help because you won’t always be sure if the issue lies with your Python code, with how you’re using a library, or something else you haven’t considered. Think of learning Python like learning to drive on the highway: even if you’re excited to to take long road trips, you first need to understand how to operate the car.

Some good resources to learn Python include:

For guidance on the pros and cons of different methods aimed at beginners learning to code, check out 5 Best Ways to Learn to Code.

Here’s how each of our four students chose to begin learning Python:

Katarina - Bootcamp

Katarina isn’t new to programming. She finds a bootcamp that focuses specifically on using Python for data science. She begins learning how to lay the groundwork in Python, and because the bootcamp she chose focuses on basics of using Python for data science, rather than others that jump right into more advanced topics in data science, she begins to build a solid foundation.

Devonte - Textbook

Python isn’t Devonte’s first programming language, so he understands that Python is one of the most popular, used in widely varied modern technologies. Since he knows a bit about how the language works already, and needs to develop a deeper understanding of it’s capabilities, Devonte reads Automate the Boring Stuff with Python, which covers the basics of Python in a way that sets him up to do automation.

Tim - Online tutorial

Tim is a math whiz, and has dabbled in coding before, so approaching a programming language is easy for him. The functionality he hopes to build into his web app for the animal shelter is well-covered by a few Python libraries he has discovered, so he decides to start with the official Python tutorial.

Priya - Tutor

Priya’s mom is excited about her daughter’s ambition to learn and hires a tutor. They live in the country, so meeting a tutor online saves them a long drive. Because Priya loves art, her tutor uses Turtle - a popular way for introducing programming to kids - to teach her coding basics in a visual way.

Getting Unstuck

An important skill when you’re learning Python is learning what to do when you get stuck.

And you will get stuck. Relax, it’s part of the learning process.

Maybe you’re typing in an example and you get a syntax error, despite being pretty sure you typed everything correctly. Or maybe you wrote your first program from scratch, and it’s not doing what you want. Since there are lots of little roadblocks with any language, Python included, think of them as opportunities to improve. Getting stuck means you get lots of practice right away, which is good, if a little frustrating.

When you’re really stuck, it’s a great time to hire a tutor. Having another set of eyes is a good way to solve programming problems, and a tutor can help you explain the underlying problem. You can also reach out to communities like the Learn Python subreddit, or the Python discord. If you’re taking a class, ask for help from your classmates.

Other useful techniques for fixing issues include:

  • Step away from a Python coding problem so you can approach it with fresh eyes.

  • Put print statements in your code to check that variables are being set as you expect.

  • Comment out lines of code to eliminate the code that is causing an error.

As you grow more comfortable and write more complicated programs, consider learning a debugger like pdb, pudb, or the one built into PyCharm or Visual Studio Code.

Our students use different methods to problem-solve, each one specific to their own issue:

Katarina

Katarina is getting an error while trying to do some basic statistics on weather data. She trades her assignment to her classmate, Theryn. Theryn notices Katarina didn’t convert some columns to integers, which caused issues when she tried to perform mathematical operations. Katarina notices Theryn accidentally used the same variable for two different things, meaning the first value was overwritten. Together, they solve the issue.

Devonte

Devonte is only partway through the Python tutorial, but he decides to give it a try to see if he can get a very basic program that lists the latest database backup working on a server. However, he gets a syntax error when he tries to run it on the work server, despite it working perfectly from his home computer. He researches the syntax error online, and realizes that his server runs Python 2, rather than Python 3. He changes the command so his script runs using Python 3 and makes a note to look into whether Python 2 is still supported by his operating system vendor.

Tim

Tim rewrites a simple “Hello World” example to use function…but nothing happens. He decides to hire a tutor with experience using Python in a similar workplace, who reminds him that he needs to call the function he defined. While this is a simple fix, Tim also uses the opportunity to clarify the difference between local and global variables.

Priya

Priya is adding more shapes to her Python script, but the shapes keep displaying drawn on top of each other. Her tutor reminds her to clear the screen - a manual step in Turtle - and voila! The problem of overlapping shapes is solved.

Time to Run

Now’s the time you’ve been waiting for: time to learn the specifics of the project you want to utilize Python to create.

Wait! Don’t jump right into creating your dream project. Instead, either come up with a similar idea that’s easier to execute, or focus on creating a simplified prototype. While you may be able to continue adding features to your prototype until you’re happy with how it performs, you might also have to throw it away and start over. You don’t want that happening with your actual project.

It’s best to ensure that your coding efforts will result in your desired outcome before you commit to a larger, more-detailed application of your code.

Here are some resources for learning common Python rules and applications:

All four students take different routes to learn more about coding in Python before they begin coding their big projects. Each one is a big step forward in achieving their individual programming goals:

Katarina

Katarina learns the basics of several data analysis libraries. She does some practice problems, and even conducts her own experiment to determine how higher temperatures affect her commute to school.

Devonte

Devonte starts writing some automation scripts for tasks he does on his own computer, like copying some files to his laptop for when he travels and has no internet access.

Tim

Tim creates a simple photo gallery app that has different sections for his two pets, as practice for designing something similar he can use for his animal shelter web app project.

Priya

Priya’s tutor recommends she learn Processing.py, which can be used to create animations and simple games. She starts making a program that makes shapes spin around, but the code gets confusing. Priya starts from scratch to make a space exploration game that her brother admits is actually kind of fun.

Branching Out

Because of Python’s flexibility, there are tons of options to explore other areas. This also means you can use these areas together in a straightforward manner, because they’re written in the same language: Python. For example, you could add machine learning to your website.

Once you’re comfortable with Python basics, you can look into alternate interpreters of Python besides the vanilla option, CPython. Many of these are embedded on other platforms. Jython and IronPython are integrated with the JVM (Java) and .NET Framework, and MicroPython is designed for microcontrollers and low-power processors. Other interpreters have some tradeoffs, such as PyPy. It’s built for speed. Stackless Python is built for applications that are highly parallel.

The most useful advice for expanding your knowledge of Python is to pay attention to your ideas and how Python may suit your goals. If you want a thorough idea of all the possibilities of what Python offers, try Awesome Python, a “curated list of awesome Python frameworks, libraries, software and resources.”

Here’s what our Python students achieved after having taken the proper steps to learn Python:

Katarina

Katarina created several machine learning models. To make results more readily available, she also learned Flask framework to create a small dashboard.

Devonte

After working hard to learn Python, Devonte was much more confident teaching himself the new simple IT automation tool. His company replaced a number of their servers, and Devonte chose to learn Ansible. A few months into writing code for that platform, he found a bug. Since his work was written in Python, Devonte was able to confidently fix it himself.

Tim

Tim got his web app working, and the animal shelter was very happy with how it automatically posts pet pictures to their social media channels. He decided to learn Javascript to make the shelter’s website even more useful and interactive. Having already learned Python, he’s easily able to apply many of the same concepts.

Priya

Priya loved learning about coding, and wanted to experiment with adding music to her animations, so her tutor helped her pick up EarSketch to record some tracks. Not only did she have a ton of fun, she learned an extremely valuable skill that will help her in high school and beyond.

Start learning

While our students are make-believe, their approaches, struggles, and goals are realistic. Hopefully, they made the process of learning Python as a beginner more real to you. They also illustrate the different destinations “learning Python” can result in. While it is a single unified language, its large community has applied it to many different things, making it both a useful language for students learning their first programming language or professionals looking to add a second.

For newcomers and seasoned coders alike, Python is easy to learn and use. In fact, it’s one of the most accessible programming languages someone can learn. Simplified syntax, an emphasis on natural language, and easy application makes Python a valuable coding language for anyone to learn.