Python, currently the most popular programming language, is a free, open-source, general-purpose language. If you’re looking to learn Python, we have a ton of articles for you! What we’ll do in this article is organize these resources for you, since some are more appropriate for beginners to the Python language or to even programming languages in general. If you’re a beginner, there are lots of introductory lessons here for you! On the other hand, there are other articles that target experienced programmers too, as well as those using Python for data science and machine learning.
Many of our resources for beginners especially are complete tutorials with exercises to help you practice what you’ve learned. Some of the resources for experienced readers dive right into the practice exercises. Whether you’re just learning to code or a veteran of many years, we believe that nothing helps you progress faster in your learning than a good example.
Python Programming for Beginners
Tools and First Steps for Writing Python Code
- Thonny: The Most Beginner Friendly Python IDE
For beginners looking for an IDE that has good basic features and an absolutely no-hassle install process, Thonny is a great choice. Thonny lets you start learning Python right away without a lot of complicated setup work.
- PyCharm vs. VS Code: Which Is Better and Why?
If you feel you need a more dedicated IDE than Jupyter Notebook, I’ve had great success with Both PyCharm (which comes in a free community edition) and VS Code. Of the two, PyCharm is a dedicated Python IDE, so there’s less setup involved to get it to work out of the box with Python.
Python Beginner Tutorials and Exercises
The lessons in the articles below are focused on beginners.
- Python Operators: The Building Blocks of Successful Code
Most beginners start their programming journey by printing “Hello world” and working with simple variables and operators. This article starts with operators you already know from math classes and using a calculator, and moves on to operators that are specific to the Python programming language. We then learn about how to assign values to variables, both using the simple assignment and the compound assignment operators. Your learning journey continues with material on the comparison operators, the Python identity operators, and which operators “short circuit” (spoiler alert: that sounds a lot worse than it is)!
- Boolean Expressions in Python (Tutorial with Exercises)
This tutorial is about expressions that are either true or false, branching, and making decisions. You learn all about if statements, Boolean (True/False) expressions using comparison operators, combing and extending Boolean operations with and, or and not.
- Python Lists for Beginners: A Complete Lesson with Exercises
The list is one of the most heavily used and flexible of the Python collections classes. In this lesson, you’ll understand how to use lists, create them dynamically using either loops or list comprehensions, and use the most heavily used of Python’s iteration control flow structures, the for loop. (Lists are a great place to introduce the looping constructs in Python.). You’ll also learn about how to use Python’s range function and Python’s powerful slicing mechanism, a powerful syntax for getting a subset of the list.
- The Python For Loop: Complete Tutorial With Exercises
We first introduced the for loop in the context of the Python lists article. In this article, we dig deeper into the for loop, including topics such as the difference between for and while, for loop best practices, using a for loop with a Python dictionary, the enumerate function, nested loops, and many others.
- Python Dictionaries for Beginners: A Complete Lesson with Exercises
Once you’ve tackled lists, you’re ready to move on to the other workhorse collection class that’s built into Python: the dictionary. You’ll learn about how to create dictionaries and append values, how dictionaries optimize lookup performance, what to do about missing values, and how to implement counters using a related class, defaultdict.
- Python String Formatting: Beginner to Expert
String formatting is an important task in any programming language, and Python handles it brilliantly, especially with formatted string literals (“f-strings”). This tutorial covers f-strings in-depth, along with another, compatible way of formatting strings that’s also quite possible. You’ll learn how to convert numbers to strings, control the formatting of decimals, align strings in various ways, and other techniques.
- Python Functions
Admittedly this article on Python functions might be a bit rigorous if you’re just starting out, so we may follow it up with a companion piece. That said, the strength of this article is that you’ll learn all about function arguments and positional and named parameters, one of the most flexible and interesting features of the Python programming language.
- Python Date and Time Functions: The Complete Tutorial
It’s about time! And dates. And lots more. This article includes several tutorial lessons and examples, focused primarily on Python’s powerful datetime module, but also including information about the built-in zoneinfo module, other related Python modules, and a special section devoted to the third-party dateutil module. Learn about formatting and parsing dates, finding the difference between two dates, and calculating past or future dates based on timedelta offsets. Need a recurring schedule of events or want to know how many days until Christmas? We have a lot of great stuff in this comprehensive guide.
- Python Classes: Tutorial With Exercises
In Python, everything you deal with — even number literals — are objects. At some point, however, we want to go beyond the classes that Python itself provides and start creating our own custom classes and objects. This article introduces you to object-oriented concepts and best practices and how to implement them in Python.
- What Is a Python Package?
Have you ever been stumped by a ModuleNotFoundError? Not anymore! Learning to import modules and packages is crucial to getting you past “Hello World.” This article clears up the confusion around packages and modules. You’ll learn how Python finds packages, the right way to create virtual environments and install packages, and even how to create your own packages.
General Beginner Programming Topics
- How to Learn to Program
You may have many questions and doubts if you’re new to programming. Am I too old to start programming? (By the way, I was thirty when I began, which led to a successful 30+ year career). Can you do it on your own with online lessons? What should you think about first?
- Learn Basic Command Line Skills and Rock Your Workflow
- How to Practice Python
Python is a relatively easy language to learn for experienced developers, but we strongly recommend studying the language in-depth and lots of practice for newcomers to programming! But as with many good habits, sometimes we have good intentions, but we don’t follow through. This article offers many tips for building your Python practice habit and is based on recent research about habit formation.
Learn Python Data Science
We have several articles of interest to those interested in learning and using the Python data science tools.
- Jupyter Notebook: A Complete Introduction
We love Jupyter Notebook because it lets us share code with our readers. It’s also a widely used tool, especially in the Data Science community. We recommend getting to know this tool because many of our tutorials come with free Jupyter Notebook exercises you can use and run. You can use it online or install it locally.
- NumPy Examples: Forty-Five Practice Questions To Make You an Expert
The foundation of many popular Python data science tools like Pandas as well as SciPy and a host of others, NumPy is a core library that all students of data science should learn to use well. This post — one of our most popular — helps you brush up your NumPy skills with forty-five exercises designed to get you thinking, looking things up, and mastering NumPy!
- Pandas Examples and Review Questions to Make You an Expert
Like many Python developers, I first learned about NumPy while learning about Pandas, so I wrote this companion piece to the NumPy article. Again I took the approach of creating a set of “open-book” exercises you can use to help review core Pandas concepts.
- Is Julia Easy to Learn for Python Programmers?
Ready to try something new? Did you know that Jupyter Notebook is an acronym for the languages it originally supported: Julia, Python, and R? Julia is a fast language that’s popular among data scientists, and we found it extremely accessible, being very similar to Python in man respects!
The Python Programming Language: Articles for The Intermediate and Experienced Programmer
- Useful Collection Classes in Python You May Not Know
The Python standard library has a lot of great collection classes beyond the workhorse list and dictionary that most of us learn when we first encounter the language. In this article, you’ll learn all about Queue, Defaultdict, Sets, NamedTuple, and get an overview of many mutable and non-mutable Python collections.
- Python Dataclass – Easily Automate Class Best Practices
The Python programming language features many special “magic methods” that can be used to make your user-defined classes act like they were part of the language from the beginning. Python dataclasses make it easy to implement these methods automatically, which not only saves you time right away but means you won’t have to spend time maintaining these methods in the future.
- Python JSON: Easily work with Dictionaries, Files, and Custom Objects
Especially when it comes to working with dictionaries, Python’s facilities for reading and writing JSON strings or files could hardly be simpler to use. In this article, we cover both basic JSON processing and some advanced, custom use cases.
- Python Dunder Methods: The Ugliest Awesome Sauce
Other than its simplicity, those of us who love Python are sometimes in awe of its consistency. Perhaps that’s part of what has made this our most popular article! This consistency is no accident but relies on the Python data model, and special “magic methods” — those methods with the ugly double underbars in front and behind like __str__, __repr__, __eq__ and the like. Mastering dunder methods is how we go from writing adequate Python code to code that looks like it was built into the library itself.
- How Do I Profile Python Code
This is a complete introduction with tutorial and examples on a variety of Python code profilers and benchmarking tools, from built-in tools like cprofile and timeit, to many third-party open source profiles including line_profiler and memory_profiler.
- How to Use Docker with Python
In this article plus GitHub repository, we provide several working examples to help you learn Python and Docker, focusing on web development. We begin with a simple Python flask example container, and move on to a more complex Docker Compose example of a full Django and Postgresql starter project.