Python tutorials

Using the Python and Operator

Python has three Boolean operators, or logical operators: and, or, and not. You can use them to check if certain conditions are met before deciding the execution path your programs will follow. In this video course, you’ll learn about the and operator and how to use it in your code. In this video course, you’ll learn how to: Understand the logic behind Python’s and operator Build and understand Boolean and non-Boolean expressions that use the and operator Use the and […]

Read more

Python 3.11 Preview: TOML and tomllib

Python 3.11 is getting closer to its final release, which will happen in October 2022. The new version is currently going through beta testing, and you can install it yourself to preview and test some of the new features, including support for reading TOML with the new tomllib module. TOML is a configuration file format that’s getting more and more popular in the Python ecosystem. This is driven by the adoption of pyproject.toml as the central configuration file in Python […]

Read more

Python Stacks, Queues, and Priority Queues in Practice

Queues are the backbone of numerous algorithms found in games, artificial intelligence, satellite navigation, and task scheduling. They’re among the top abstract data types that computer science students learn early in their education. At the same time, software engineers often leverage higher-level message queues to achieve better scalability of a microservice architecture. Plus, using queues in Python is simply fun! Python provides a few built-in flavors of queues that you’ll see in action in this tutorial. You’re also going to […]

Read more

Building a Site Connectivity Checker

Building a site connectivity checker in Python is an interesting project to level up your skills. With this project, you’ll integrate knowledge related to handling HTTP requests, creating command-line interfaces (CLI), and organizing your application’s code using common Python project layout practices. By building this project, you’ll learn how Python’s asynchronous features can help you deal with multiple HTTP requests efficiently. In this video course, you’ll learn how to: Create command-line interfaces (CLI) using Python’s argparse Check if a website […]

Read more

Build a Tic-Tac-Toe Game With Python and Tkinter

Playing computer games is a great way to unwind or challenge yourself. Some people even do it professionally. It’s also fun and educational to build your own computer games. In this tutorial, you’ll build a classic tic-tac-toe game using Python and Tkinter. With this project, you’ll go through the thought processes required for creating your own game. You’ll also learn how to integrate your diverse programming skills and knowledge to develop a functional and fun computer game. In this tutorial, […]

Read more

Effective Python Testing With Pytest

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: Testing Your Code With pytest Testing your code brings a wide variety of benefits. It increases your confidence that the code behaves as you expect and ensures that changes to your code won’t cause regressions. Writing and maintaining tests is hard work, so you should leverage all the tools at your disposal to make […]

Read more

Why new Macs break your Docker build, and how to fix it

One of the promises of Docker is reproducibility: you can build an image on a different machine, and assuming you’ve done the appropriate setup, get the same result. So it can be a little confusing when you try to build your Python-based Dockerfile on a new Mac, and everything starts failing. What used to work before—on an older Mac, or on a Linux machine—fails in completely unexpected ways. The problem is that the promise of reproducibility relies on certain invariants […]

Read more

Python mmap: Doing File I/O With Memory Mapping

The Zen of Python has a lot of wisdom to offer. One especially useful idea is that “There should be one—and preferably only one—obvious way to do it.” Yet there are multiple ways to do most things in Python, and often for good reason. For example, there are multiple ways to read a file in Python, including the rarely used mmap module. Python’s mmap provides memory-mapped file input and output (I/O). It allows you to take advantage of lower-level operating […]

Read more

How Can You Emulate Do-While Loops in Python?

If you came to Python from a language like C, C++, Java, or JavaScript, then you may be missing their do-while loop construct. A do-while loop is a common control flow statement that executes its code block at least once, regardless of whether the loop condition is true or false. This behavior relies on the fact that the loop condition is evaluated at the end of each iteration. So, the first iteration always runs. One of the most common use […]

Read more

Build Your Python Project Documentation With MkDocs

In this tutorial, you’ll learn how to quickly build documentation for a Python package using MkDocs and mkdocstrings. These tools allow you to generate nice-looking and modern documentation from Markdown files and your code’s docstrings. Maintaining auto-generated documentation means less effort because you’re linking information between your code and the documentation pages. However, good documentation is more than just the technical description pulled from your code! Your project will appeal more to users if you guide them through examples and […]

Read more
1 89 90 91 92 93 181