Python tutorials

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

Quiz: Python 3.14 Preview: Template Strings (T-Strings)

Interactive Quiz ⋅ 11 QuestionsBy Leodanis Pozo Ramos Share Evaluate your grasp of Python’s t-strings, which provide a structured and secure way to handle string templates. The quiz contains 11 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

Python 3.14 Preview: Template Strings (T-Strings)

Python 3.14’s t-strings allow you to intercept and transform input values before assembling them into a final representation. Unlike f-strings, which produce a str object, t-strings resolve to a Template instance, allowing you to safely process and customize dynamic content. One of the key benefits of t-strings is their ability to help prevent security vulnerabilities like SQL injection and XSS attacks. They’re also valuable in other fields that rely on string templates, such as structured logging. By the end of […]

Read more

Implementing the Factory Method Pattern in Python

This video course explores the Factory Method design pattern and its implementation in Python. Design patterns became a popular topic in late 90s after the so-called Gang of Four (GoF: Gamma, Helm, Johson, and Vlissides) published their book Design Patterns: Elements of Reusable Object-Oriented Software. The book describes design patterns as a core design solution to reoccurring problems in software and classifies each design pattern into categories according to the nature of the problem. Each pattern is given a name, […]

Read more

Quiz: Use TorchAudio to Prepare Audio Data for Deep Learning

Interactive Quiz ⋅ 10 QuestionsBy Bartosz Zaczyński Share In this quiz, you’ll test your understanding of audio fundamentals and how to Use TorchAudio to Prepare Audio Data for Deep Learning. You’ll revisit fundamental terminology and how to: Install and import TorchAudio Load audio waveform datasets Apply signal transforms Work through these questions to check your knowledge about building audio workflows for machine learning in Python. The quiz contains 10 questions and there is no time limit. You’ll get 1 point […]

Read more
1 2 3 194