Python tutorials

Python Scope and the LEGB Rule: Resolving Names in Your Code

The scope of a variable in Python determines where in your code that variable is visible and accessible. Python has four general scope levels: local, enclosing, global, and built-in. When searching for a name, Python goes through these scopes in order. It follows the LEGB rule, which stands for Local, Enclosing, Global, and Built-in. Understanding how Python manages the scope of variables and names is a fundamental skill for you as a Python developer. It helps you avoid unexpected behavior […]

Read more

Getting Started With marimo Notebooks

marimo notebooks redefine the notebook experience by offering a reactive environment that addresses the limitations of traditional linear notebooks. With marimo, you can seamlessly reproduce and share content while benefiting from automatic cell updates and a correct execution order. Discover how marimo’s features make it an ideal tool for documenting research and learning activities. By the end of this video course, you’ll understand that: marimo notebooks automatically update dependent cells, ensuring consistent results across your work. Reactivity allows marimo to […]

Read more

Quiz: How to Debug Common Python Errors

Interactive Quiz ⋅ 7 QuestionsBy Geir Arne Hjelle Share In this quiz, you’ll test your understanding of How to Debug Common Python Errors. Debugging means identifying, analyzing, and resolving issues in your Python code. You’ll revisit reading tracebacks, using print() for value tracking, setting breakpoints to pause execution, and writing tests to catch errors. Good luck! 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 […]

Read more

How to Debug Common Python Errors

Python debugging involves identifying and fixing errors in your code using tools like tracebacks, print() calls, breakpoints, and tests. In this tutorial, you’ll learn how to interpret error messages, use print() to track variable values, and set breakpoints to pause execution and inspect your code’s behavior. You’ll also explore how writing tests can help prevent errors and ensure your code runs as expected. By the end of this tutorial, you’ll understand that: Debugging means identifying, analyzing, and resolving issues in […]

Read more

Quiz: What Is Python’s __init__.py For?

Interactive Quiz ⋅ 7 QuestionsBy Martin Breuss Share In this quiz, you’ll test your knowledge of Python’s __init__.py file. Understanding this file’s role will help you create more organized and reusable Python code. 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. The maximum score is 100%. Good luck! Related Resources

Read more

What Is Python’s __init__.py For?

Python’s special __init__.py file marks a directory as a regular Python package and allows you to import its modules. This file runs automatically the first time you import its containing package. You can use it to initialize package-level variables, define functions or classes, and structure the package’s namespace clearly for users. By the end of this tutorial, you’ll understand that: A directory without an __init__.py file becomes a namespace package, which behaves differently from a regular package and may cause […]

Read more

Exploring Protocols in Python

In Python, a protocol specifies the methods and attributes that a class must implement to be considered of a given type. Protocols are important in Python’s type hint system, which allows for static type checking through external tools, such as mypy, Pyright, and Pyre. Before there were protocols, these tools could only check for nominal subtyping based on inheritance. There was no way to check for structural subtyping, which relies on the internal structure of classes. This limitation affected Python’s […]

Read more

Free-Threaded Python Unleashed and Other Python News for July 2025

Last month was a watershed moment for Python. Python 3.14 beta 3, released mid-June, isn’t just another pre-release. It’s the first build in which the long-awaited free-threaded or “no-GIL” variant is officially supported. That’s right: a no-GIL Python is finally taking shape. The interpreter isn’t the only thing making headlines, though. Below you’ll find a curated tour of the latest Python developments, broken down by area so you can zero in on your favorite topic. Core Python Development CPython’s core […]

Read more

330× faster: Four different ways to speed up your code

Note: The original version of this article was slightly different, e.g. with 500x speedup; I reworked it to make the argument clearer. If your Python code is slow and needs to be fast, there are many different approaches you can take, from parallelism to writing a compiled extension. But if you just stick to one approach, it’s easy to miss potential speedups, and end up with code that is much slower than it could be. To make sure you’re not […]

Read more

500× faster: Four different ways to speed up your code

If your Python code is slow and needs to be fast, there are many different approaches you can take, from parallelism to writing a compiled extension. But if you just stick to one approach, it’s easy to miss potential speedups, and end up with code that is much slower than it could be. To make sure you’re not forgetting potential sources of speed, it’s useful to think in terms of practices. Each practice: Speeds up your code in its own […]

Read more
1 2 3 195