Python tutorials

Python Thread Safety: Using a Lock and Other Techniques

Python threading allows you to run parts of your code concurrently, making the code more efficient. However, when you introduce threading to your code without knowing about thread safety, you may run into issues such as race conditions. You solve these with tools like locks, semaphores, events, conditions, and barriers. By the end of this tutorial, you’ll be able to identify safety issues and prevent them by using the synchronization primitives in Python’s threading module to make your code thread-safe. […]

Read more

Quiz: Pydantic: Simplifying Data Validation in Python

Interactive Quiz ⋅ 9 QuestionsBy Martin Breuss Share In this quiz, you’ll test your understanding of Pydantic. Pydantic is a powerful data validation library for Python. You can also use a related library, pydantic-settings, for settings management. By working through this quiz, you’ll revisit how to work with data schemas with Pydantic’s BaseModel, write custom validators for complex use cases, validate function arguments with Pydantic’s @validate_call, and manage settings and configure applications with pydantic-settings. The quiz contains 9 questions and […]

Read more

Understanding Python’s Global Interpreter Lock (GIL)

The Python Global Interpreter Lock or GIL, in simple words, is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter. This means that only one thread can be in a state of execution at any point in time. The impact of the GIL isn’t visible to developers who execute single-threaded programs, but it can be a performance bottleneck in CPU-bound and multi-threaded code. Since the GIL allows only one thread to […]

Read more

Quiz: Single and Double Underscores in Python Names

Interactive Quiz ⋅ 9 QuestionsBy Leodanis Pozo Ramos Share In this quiz, you’ll test your understanding of Single and Double Underscores in Python Names. By working through this quiz, you’ll revisit Python naming conventions that rely on using underscores (_), how to differentiate public and non-public names by using a single leading underscore, how to use double leading underscores to leverage name mangling in Python classes, and other common uses of underscores in Python names. The quiz contains 9 questions […]

Read more

Should you use uv’s managed Python in production?

The uv Python packaging tool provides fast replacements for tools like pip, and a variety of developer experience improvements. Unlike most Python packaging tools, uv doesn’t require Python to be installed to use it. Building on that ease of installation, one of its interesting and useful features is the ability to install Python for you. As a developer, this is great: if you need a version of Python you don’t have installed, uv can install it for you (transparently, by […]

Read more

Quiz: Getting Started With Async Features in Python

Interactive Quiz ⋅ 7 QuestionsBy Martin Breuss Share In this quiz, you’ll test your understanding of Asynchronous Programming in Python. By working through this quiz, you’ll revisit the concepts of synchronous and asynchronous programs, why you might want to write an asynchronous program, and how to use Python async features. The quiz contains 7 questions and there is no time limit. You’ll get 1 point for each correct answer. At the end of the quiz, you’ll receive a total score. […]

Read more

Structural Pattern Matching in Python

Structural pattern matching is a powerful control flow construct invented decades ago that’s traditionally used by compiled languages, especially within the functional programming paradigm. Most mainstream programming languages have since adopted some form of pattern matching, which offers concise and readable syntax while promoting a declarative code style. Although Python was late to join the party, it introduced structural pattern matching in the 3.10 release. Getting to Know Structural Pattern Matching Before taking advantage of structural pattern matching in your […]

Read more

Using Type Hints for Multiple Return Types in Python

In Python, type hinting is an optional yet useful feature for making your code easier to read, reason about, and debug. With type hints, you let other developers know the expected data types for variables, function arguments, and return values. As you write code for applications that require greater flexibility, you may need to specify multiple return types to make your code more robust and adaptable to different situations. You’ll encounter different use cases where you may want to annotate […]

Read more

Quiz: Python Thread Safety: Using a Lock and Other Techniques

Interactive Quiz ⋅ 8 QuestionsBy Martin Breuss Share In this quiz, you’ll test your understanding of Python threading and thread safety. You’ll revisit concepts such as race conditions, thread safety issues, and synchronization primitives in the threading module. This knowledge is crucial when working with multithreaded code using Python’s threading module and ThreadPoolExecutor. The quiz contains 8 questions and there is no time limit. You’ll get 1 point for each correct answer. At the end of the quiz, you’ll receive […]

Read more

Syntactic Sugar: Why Python Is Sweet and Pythonic

Python has several pieces of syntax that are syntactic sugar. This sugar is syntax that isn’t strictly necessary but gives Python some of its flavor as a readable, beginner-friendly, and powerful language. In this tutorial, you’ll explore some of Python’s most used pieces of syntactic sugar. In practice, you already use most of these pieces of syntax, as they include many well-known Pythonic constructs. As you read on, you’ll see how Python works under the hood and learn how to […]

Read more
1 3 4 5 6 7 182