<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>Real Python</title>
  <link href="https://realpython.com/atom.xml" rel="self"/>
  <link href="https://realpython.com/"/>
  <updated>2025-07-30T14:00:00+00:00</updated>
  <id>https://realpython.com/</id>
  <author>
    <name>Real Python</name>
  </author>

  
    <entry>
      <title>Python&#x27;s asyncio: A Hands-On Walkthrough</title>
      <id>https://realpython.com/async-io-python/</id>
      <link href="https://realpython.com/async-io-python/"/>
      <updated>2025-07-30T14:00:00+00:00</updated>
      <summary>Explore how Python asyncio works and when to use it. Follow hands-on examples to build efficient programs with coroutines and awaitable tasks.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;asyncio&lt;/code&gt; library enables you to write concurrent code using the &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt; keywords. The core building blocks of async I/O in Python are awaitable objects—most often coroutines—that an event loop schedules and executes asynchronously. This programming model lets you efficiently manage multiple I/O-bound tasks within a single thread of execution.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll learn how Python &lt;code&gt;asyncio&lt;/code&gt; works, how to define and run coroutines, and when to use asynchronous programming for better performance in applications that perform I/O-bound tasks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Python’s &lt;strong&gt;&lt;code&gt;asyncio&lt;/code&gt;&lt;/strong&gt; provides a framework for writing single-threaded &lt;strong&gt;concurrent code&lt;/strong&gt; using &lt;strong&gt;coroutines&lt;/strong&gt;, &lt;strong&gt;event loops&lt;/strong&gt;, and &lt;strong&gt;non-blocking I/O operations&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;For I/O-bound tasks, async I/O &lt;strong&gt;can often outperform multithreading&lt;/strong&gt;—especially when managing a large number of concurrent tasks—because it avoids the overhead of thread management.&lt;/li&gt;
&lt;li&gt;You should use &lt;code&gt;asyncio&lt;/code&gt; when your application spends significant time waiting on &lt;strong&gt;I/O operations&lt;/strong&gt;, such as network requests or file access, and you want to &lt;strong&gt;run many of these tasks concurrently&lt;/strong&gt; without creating extra threads or processes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Through hands-on examples, you’ll gain the practical skills to write efficient Python code using &lt;code&gt;asyncio&lt;/code&gt; that scales gracefully with increasing I/O demands.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/async-io-python-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-async-io-python-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to learn about async I/O in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Python&#x27;s asyncio: A Hands-On Walkthrough” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/async-io-python/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #ffc873;&quot; alt=&quot;Async IO in Python: A Complete Walkthrough&quot; src=&quot;https://files.realpython.com/media/A-Complete-Walkthrough-of-Pythons-Asyncio_Watermarked.5b6b9a01fdc9.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/A-Complete-Walkthrough-of-Pythons-Asyncio_Watermarked.5b6b9a01fdc9.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/A-Complete-Walkthrough-of-Pythons-Asyncio_Watermarked.5b6b9a01fdc9.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/A-Complete-Walkthrough-of-Pythons-Asyncio_Watermarked.5b6b9a01fdc9.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/A-Complete-Walkthrough-of-Pythons-Asyncio_Watermarked.5b6b9a01fdc9.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/async-io-python/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python&#x27;s asyncio: A Hands-On Walkthrough&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your knowledge of `asyncio` concurrency with this quiz that covers coroutines, event loops, and efficient I/O-bound task management.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;a-first-look-at-async-io&quot;&gt;A First Look at Async I/O&lt;a class=&quot;headerlink&quot; href=&quot;#a-first-look-at-async-io&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before exploring &lt;code&gt;asyncio&lt;/code&gt;, it’s worth taking a moment to compare async I/O with other concurrency models to see how it fits into Python’s broader, sometimes dizzying, landscape. Here are some essential concepts to start with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Parallelism&lt;/strong&gt; consists of executing multiple operations at the same time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiprocessing&lt;/strong&gt; is a means of achieving parallelism that entails spreading tasks over a computer’s central processing unit (CPU) cores. Multiprocessing is well-suited for CPU-bound tasks, such as tightly bound &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loops&lt;/a&gt; and mathematical computations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrency&lt;/strong&gt; is a slightly broader term than parallelism, suggesting that multiple tasks have the ability to run in an overlapping manner. Concurrency doesn’t necessarily imply parallelism.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Threading&lt;/strong&gt; is a concurrent execution model in which multiple threads take turns executing tasks. A single process can contain multiple threads. Python’s relationship with threading is complicated due to the &lt;a href=&quot;https://realpython.com/python-gil/&quot;&gt;global interpreter lock (GIL)&lt;/a&gt;, but that’s beyond the scope of this tutorial.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Threading is good for &lt;a href=&quot;/ref/glossary/io-bound-task/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;I/O-bound tasks&lt;/strong&gt;&lt;/a&gt;. An I/O-bound job is dominated by a lot of waiting on &lt;a href=&quot;/ref/glossary/input-output/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;input/output (I/O)&lt;/strong&gt;&lt;/a&gt; to complete, while a &lt;a href=&quot;/ref/glossary/cpu-bound-task/&quot; class=&quot;ref-link&quot;&gt;CPU-bound task&lt;/a&gt; is characterized by the computer’s cores continually working hard from start to finish.&lt;/p&gt;
&lt;p&gt;The Python &lt;a href=&quot;/ref/glossary/standard-library/&quot; class=&quot;ref-link&quot;&gt;standard library&lt;/a&gt; has offered longstanding &lt;a href=&quot;https://docs.python.org/3/library/concurrency.html&quot;&gt;support for these models&lt;/a&gt; through its &lt;code&gt;multiprocessing&lt;/code&gt;, &lt;code&gt;concurrent.futures&lt;/code&gt;, and &lt;code&gt;threading&lt;/code&gt; packages.&lt;/p&gt;
&lt;p&gt;Now it’s time to add a new member to the mix. In recent years, a separate model has been more comprehensively built into &lt;a href=&quot;https://realpython.com/cpython-source-code-guide/&quot;&gt;CPython&lt;/a&gt;: &lt;strong&gt;asynchronous I/O&lt;/strong&gt;, commonly called &lt;strong&gt;async I/O&lt;/strong&gt;. This model is enabled through the standard library’s &lt;a href=&quot;/ref/stdlib/asyncio/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;&lt;code&gt;asyncio&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; package and the &lt;a href=&quot;https://realpython.com/python-keywords/#the-async-keyword&quot;&gt;&lt;code&gt;async&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-keywords/#the-await-keyword&quot;&gt;&lt;code&gt;await&lt;/code&gt;&lt;/a&gt; keywords.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Async I/O isn’t a new concept. It exists in—or is being built into—other languages such as &lt;a href=&quot;https://gobyexample.com/goroutines&quot;&gt;Go&lt;/a&gt;, &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/csharp/async&quot;&gt;C#&lt;/a&gt;, and &lt;a href=&quot;https://doc.rust-lang.org/book/ch17-00-async-await.html&quot;&gt;Rust&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;asyncio&lt;/code&gt; package is billed by the Python documentation as a &lt;a href=&quot;https://docs.python.org/3/library/asyncio.html&quot;&gt;library to write concurrent code&lt;/a&gt;. However, async I/O isn’t threading or multiprocessing. It’s not built on top of either of these.&lt;/p&gt;
&lt;p&gt;Async I/O is a single-threaded, single-process technique that uses &lt;a href=&quot;https://en.wikipedia.org/wiki/Cooperative_multitasking&quot;&gt;cooperative multitasking&lt;/a&gt;. Async I/O gives a feeling of concurrency despite using a single thread in a single process. &lt;a href=&quot;/ref/glossary/coroutine/&quot; class=&quot;ref-link&quot;&gt;Coroutines&lt;/a&gt;—or &lt;strong&gt;coro&lt;/strong&gt; for short—are a central feature of async I/O and can be scheduled concurrently, but they’re not inherently concurrent.&lt;/p&gt;
&lt;p&gt;To reiterate, async I/O is a model of concurrent programming, but it’s not parallelism. It’s more closely aligned with threading than with multiprocessing, but it’s different from both and is a standalone member of the concurrency ecosystem.&lt;/p&gt;
&lt;p&gt;That leaves one more term. What does it mean for something to be &lt;strong&gt;asynchronous&lt;/strong&gt;? This isn’t a rigorous definition, but for the purposes of this tutorial, you can think of two key properties:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Asynchronous routines&lt;/strong&gt; can &lt;em&gt;pause&lt;/em&gt; their execution while waiting for a result and allow other routines to run in the meantime.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Asynchronous code&lt;/strong&gt; facilitates the concurrent execution of tasks by coordinating asynchronous routines.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here’s a diagram that puts it all together. The white terms represent concepts, and the green terms represent the ways they’re implemented:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/Screen_Shot_2018-10-17_at_3.18.44_PM.c02792872031.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block w-70&quot; src=&quot;https://files.realpython.com/media/Screen_Shot_2018-10-17_at_3.18.44_PM.c02792872031.jpg&quot; width=&quot;504&quot; height=&quot;411&quot; srcset=&quot;/cdn-cgi/image/width=126,format=auto/https://files.realpython.com/media/Screen_Shot_2018-10-17_at_3.18.44_PM.c02792872031.jpg 126w, /cdn-cgi/image/width=168,format=auto/https://files.realpython.com/media/Screen_Shot_2018-10-17_at_3.18.44_PM.c02792872031.jpg 168w, /cdn-cgi/image/width=252,format=auto/https://files.realpython.com/media/Screen_Shot_2018-10-17_at_3.18.44_PM.c02792872031.jpg 252w, /cdn-cgi/image/width=504,format=auto/https://files.realpython.com/media/Screen_Shot_2018-10-17_at_3.18.44_PM.c02792872031.jpg 504w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Concurrency versus parallelism&quot; data-asset=&quot;866&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Diagram Comparing Concurrency and Parallelism in Python (Threading, Async I/O, Multiprocessing)&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;For a thorough exploration of threading versus multiprocessing versus async I/O, pause here and check out the &lt;a href=&quot;https://realpython.com/python-concurrency/&quot;&gt;Speed Up Your Python Program With Concurrency&lt;/a&gt; tutorial. For now, you’ll focus on async I/O.&lt;/p&gt;
&lt;h3 id=&quot;async-io-explained&quot;&gt;Async I/O Explained&lt;a class=&quot;headerlink&quot; href=&quot;#async-io-explained&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Async I/O may seem counterintuitive and paradoxical at first. How does something that facilitates concurrent code use a single thread in a single CPU core? Miguel Grinberg’s &lt;a href=&quot;https://realpython.com/pycon-guide/&quot;&gt;PyCon&lt;/a&gt; talk explains everything quite beautifully:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Chess master Judit Polgár hosts a chess exhibition in which she plays multiple amateur players. She has two ways of conducting the exhibition: &lt;em&gt;synchronously&lt;/em&gt; and &lt;em&gt;asynchronously&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Assumptions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;24 opponents&lt;/li&gt;
&lt;li&gt;Judit makes each chess move in 5 seconds&lt;/li&gt;
&lt;li&gt;Opponents each take 55 seconds to make a move&lt;/li&gt;
&lt;li&gt;Games average 30 pair-moves (60 moves total)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Synchronous version&lt;/strong&gt;: Judit plays one game at a time, never two at the same time, until the game is complete. Each game takes &lt;em&gt;(55 + 5) * 30 == 1800&lt;/em&gt; seconds, or 30 minutes. The entire exhibition takes &lt;em&gt;24 * 30 == 720&lt;/em&gt; minutes, or &lt;strong&gt;12 hours&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Asynchronous version&lt;/strong&gt;: Judit moves from table to table, making one move at each table. She leaves the table and lets the opponent make their next move during the wait time. One move on all 24 games takes Judit &lt;em&gt;24 * 5 == 120&lt;/em&gt; seconds, or 2 minutes. The entire exhibition is now cut down to &lt;em&gt;120 * 30 == 3600&lt;/em&gt; seconds, or just &lt;strong&gt;1 hour&lt;/strong&gt;. (&lt;a href=&quot;https://youtu.be/iG6fr81xHKA?t=4m29s&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/async-io-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/async-io-python/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Working With Python&#x27;s Built-in Exceptions</title>
      <id>https://realpython.com/courses/working-builtin-exceptions/</id>
      <link href="https://realpython.com/courses/working-builtin-exceptions/"/>
      <updated>2025-07-29T14:00:00+00:00</updated>
      <summary>Learn the most common built-in Python exceptions, when they occur, how to handle them, and how to raise them properly in your code.</summary>
      <content type="html">
        &lt;p&gt;Python has a complete set of &lt;strong&gt;built-in exceptions&lt;/strong&gt; that provide a quick and efficient way to handle errors and exceptional situations in your code. Knowing the most commonly used built-in exceptions is key for you as a Python developer. This knowledge will help you debug code because each exception has a specific meaning that can shed light on your debugging process.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll also be able to handle and raise most of the built-in exceptions in your Python code, which is a great way to deal with errors and exceptional situations without having to create your own custom exceptions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Learn what &lt;strong&gt;errors&lt;/strong&gt; and &lt;strong&gt;exceptions&lt;/strong&gt; are in Python&lt;/li&gt;
&lt;li&gt;Understand how Python organizes the &lt;strong&gt;built-in exceptions&lt;/strong&gt; within a &lt;strong&gt;class hierarchy&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Explore the most &lt;strong&gt;commonly used&lt;/strong&gt; built-in exceptions&lt;/li&gt;
&lt;li&gt;Learn how to &lt;strong&gt;handle&lt;/strong&gt; and &lt;strong&gt;raise&lt;/strong&gt; built-in exceptions in your code&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Bitwise Operators in Python</title>
      <id>https://realpython.com/python-bitwise-operators/</id>
      <link href="https://realpython.com/python-bitwise-operators/"/>
      <updated>2025-07-28T14:00:00+00:00</updated>
      <summary>Learn how to use Python&#x27;s bitwise operators to manipulate individual bits of data at the most granular level.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Computers store all kinds of information as a stream of binary digits called bits. Whether you’re working with text, images, or videos, they all boil down to ones and zeros. Python’s bitwise operators let you manipulate those individual bits of data at the most granular level.&lt;/p&gt;
&lt;p&gt;You can use bitwise operators to implement algorithms such as compression, encryption, and error detection, as well as to control physical devices in your &lt;a href=&quot;https://realpython.com/python-raspberry-pi/&quot;&gt;Raspberry Pi project&lt;/a&gt; or elsewhere. Often, Python isolates you from the underlying bits with high-level abstractions. You’re more likely to find the &lt;a href=&quot;https://realpython.com/operator-function-overloading/&quot;&gt;overloaded&lt;/a&gt; flavors of bitwise operators in practice. But when you work with them in their original form, you’ll be surprised by their quirks!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Bitwise operators&lt;/strong&gt; enable manipulation of individual bits, which is crucial for low-level data handling.&lt;/li&gt;
&lt;li&gt;You can read and write &lt;strong&gt;binary data&lt;/strong&gt; in a &lt;strong&gt;platform-independent&lt;/strong&gt; way using Python.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bitmasks&lt;/strong&gt; pack and manipulate data efficiently within a single byte.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Overloading&lt;/strong&gt; bitwise operators allows custom data types to perform specific bitwise operations.&lt;/li&gt;
&lt;li&gt;You can embed &lt;strong&gt;secret messages&lt;/strong&gt; in images using least-significant bit steganography.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the complete source code for the digital watermarking example you’ll use in this tutorial, and to extract a secret treat hidden in an image, click the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-bitwise-operators/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-bitwise-operators&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code you’ll use&lt;/a&gt; to learn about bitwise operators in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Bitwise Operators in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/bitwise-operators/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #e5c5ac;&quot; alt=&quot;Bitwise Operators in Python&quot; src=&quot;https://files.realpython.com/media/Bitwise-Operators-in-Python_Watermarked.85ff8fc6a931.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Bitwise-Operators-in-Python_Watermarked.85ff8fc6a931.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Bitwise-Operators-in-Python_Watermarked.85ff8fc6a931.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Bitwise-Operators-in-Python_Watermarked.85ff8fc6a931.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Bitwise-Operators-in-Python_Watermarked.85ff8fc6a931.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/bitwise-operators/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Bitwise Operators in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your understanding of Python bitwise operators by revisiting core concepts like bitwise AND, OR, XOR, NOT, shifts, bitmasks, and their applications.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;overview-of-pythons-bitwise-operators&quot;&gt;Overview of Python’s Bitwise Operators&lt;a class=&quot;headerlink&quot; href=&quot;#overview-of-pythons-bitwise-operators&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python comes with a few different kinds of &lt;a href=&quot;https://realpython.com/python-operators-expressions/&quot;&gt;operators&lt;/a&gt; such as the arithmetic, logical, and comparison operators. You can think of them as functions that take advantage of a more compact &lt;strong&gt;prefix&lt;/strong&gt; and &lt;strong&gt;infix&lt;/strong&gt; syntax.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Python doesn’t include &lt;strong&gt;postfix&lt;/strong&gt; operators like the increment (&lt;code&gt;i++&lt;/code&gt;) or decrement (&lt;code&gt;i--&lt;/code&gt;) operators available in C.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Bitwise operators look virtually the same across different programming languages:&lt;/p&gt;
&lt;div class=&quot;table-responsive&quot;&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;amp; b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise AND&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;|&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a | b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise OR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;^&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a ^ b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise XOR (exclusive OR)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;~&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise NOT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;lt;&amp;lt; n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise left shift&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;gt;&amp;gt; n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise right shift&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, they’re denoted with strange-looking symbols instead of words. This makes them stand out in Python as slightly less verbose than what you might be used to. You probably wouldn’t be able to figure out their meaning just by looking at them.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’re coming from another programming language such as &lt;a href=&quot;https://realpython.com/oop-in-python-vs-java/&quot;&gt;Java&lt;/a&gt;, then you’ll immediately notice that Python is missing the &lt;strong&gt;unsigned right shift operator&lt;/strong&gt; denoted by three greater-than signs (&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;). &lt;/p&gt;
&lt;p&gt;This has to do with how Python &lt;a href=&quot;#integers-in-python&quot;&gt;represents integers&lt;/a&gt; internally. Since integers in Python can have an infinite number of bits, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Sign_bit&quot;&gt;sign bit&lt;/a&gt; doesn’t have a fixed position. In fact, there’s no sign bit at all in Python!&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Most of the bitwise operators are &lt;strong&gt;binary&lt;/strong&gt;, which means that they expect two operands to work with, typically referred to as the &lt;strong&gt;left operand&lt;/strong&gt; and the &lt;strong&gt;right operand&lt;/strong&gt;. Bitwise NOT (&lt;code&gt;~&lt;/code&gt;) is the only &lt;strong&gt;unary&lt;/strong&gt; bitwise operator since it expects just one operand.&lt;/p&gt;
&lt;p&gt;All binary bitwise operators have a corresponding &lt;strong&gt;compound operator&lt;/strong&gt; that performs an &lt;a href=&quot;https://realpython.com/python-assignment-operator/#augmented-assignment-operators-in-python&quot;&gt;augmented assignment&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;table-responsive&quot;&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Equivalent to&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;amp;= b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a = a &amp;amp; b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;|=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a |= b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a = a | b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;^=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a ^= b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a = a ^ b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;lt;&amp;lt;= n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a = a &amp;lt;&amp;lt; n&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;gt;&amp;gt;= n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a = a &amp;gt;&amp;gt; n&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;These are shorthand notations for updating the left operand in place.&lt;/p&gt;
&lt;p&gt;That’s all there is to Python’s bitwise operator syntax! Now you’re ready to take a closer look at each of the operators to understand where they’re most useful and how you can use them. First, you’ll get a quick refresher on the binary system before looking at two categories of bitwise operators: the bitwise &lt;strong&gt;logical&lt;/strong&gt; operators and the bitwise &lt;strong&gt;shift&lt;/strong&gt; operators. &lt;/p&gt;
&lt;h2 id=&quot;binary-system-in-five-minutes&quot;&gt;Binary System in Five Minutes&lt;a class=&quot;headerlink&quot; href=&quot;#binary-system-in-five-minutes&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before moving on, take a moment to brush up your knowledge of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Binary_number&quot;&gt;binary system&lt;/a&gt;, which is essential to understanding bitwise operators. If you’re already comfortable with it, then go ahead and jump to the &lt;a href=&quot;#bitwise-logical-operators&quot;&gt;Bitwise Logical Operators&lt;/a&gt; section below.&lt;/p&gt;
&lt;h3 id=&quot;why-use-binary&quot;&gt;Why Use Binary?&lt;a class=&quot;headerlink&quot; href=&quot;#why-use-binary&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;There are an infinite number of ways to represent numbers. Since ancient times, people have developed different notations, such as Roman numerals and Egyptian hieroglyphs. Most modern civilizations use &lt;a href=&quot;https://en.wikipedia.org/wiki/Positional_notation&quot;&gt;positional notation&lt;/a&gt;, which is efficient, flexible, and well suited for doing arithmetic.&lt;/p&gt;
&lt;p&gt;A notable feature of any positional system is its &lt;strong&gt;base&lt;/strong&gt;, which represents the number of digits available. People naturally favor the &lt;strong&gt;base-ten&lt;/strong&gt; numeral system, also known as the &lt;strong&gt;decimal system&lt;/strong&gt;, because it plays nicely with counting on fingers.&lt;/p&gt;
&lt;p&gt;Computers, on the other hand, treat data as a bunch of numbers expressed in the &lt;strong&gt;base-two&lt;/strong&gt; numeral system, more commonly known as the &lt;strong&gt;binary&lt;/strong&gt; system. Such numbers are composed of only two digits—zero and one.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-bitwise-operators/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-bitwise-operators/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Bitwise Operators in Python</title>
      <id>https://realpython.com/quizzes/bitwise-operators/</id>
      <link href="https://realpython.com/quizzes/bitwise-operators/"/>
      <updated>2025-07-28T12:00:00+00:00</updated>
      <summary>Test your understanding of Python bitwise operators by revisiting core concepts like bitwise AND, OR, XOR, NOT, shifts, bitmasks, and their applications.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the &lt;a href=&quot;https://realpython.com/python-bitwise-operators/&quot;&gt;Bitwise Operators in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to use Python&amp;rsquo;s bitwise AND (&lt;code&gt;&amp;amp;&lt;/code&gt;), OR (&lt;code&gt;|&lt;/code&gt;), XOR (&lt;code&gt;^&lt;/code&gt;), NOT (&lt;code&gt;~&lt;/code&gt;), left and right shifts (&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;), and bitmasks. You&amp;rsquo;ll also see practical examples for manipulating data at the bit level. Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #258: Supporting the Python Package Index</title>
      <id>https://realpython.com/podcasts/rpp/258/</id>
      <link href="https://realpython.com/podcasts/rpp/258/"/>
      <updated>2025-07-25T12:00:00+00:00</updated>
      <summary>What goes into supporting more than 650,000 projects and nearly a million users of the Python Package Index? This week on the show, we speak with Maria Ashna about her first year as the inaugural PyPI Support Specialist.</summary>
      <content type="html">
        &lt;p&gt;What goes into supporting more than 650,000 projects and nearly a million users of the Python Package Index? This week on the show, we speak with Maria Ashna about her first year as the inaugural PyPI Support Specialist.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python&#x27;s Requests Library (Guide)</title>
      <id>https://realpython.com/python-requests/</id>
      <link href="https://realpython.com/python-requests/"/>
      <updated>2025-07-23T14:00:00+00:00</updated>
      <summary>The Requests library is the go-to tool for making HTTP requests in Python. Learn how to use its intuitive API to send requests and interact with the web.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;The &lt;a href=&quot;https://requests.readthedocs.io/en/latest/&quot;&gt;Requests&lt;/a&gt; library is the go-to package for making HTTP requests in Python. It abstracts the complexities of making requests behind an intuitive &lt;a href=&quot;/ref/glossary/api/&quot; class=&quot;ref-link&quot;&gt;API&lt;/a&gt;. Though not part of Python’s standard library, it’s worth considering Requests to perform HTTP actions like GET, POST, and more.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Requests is not a built-in&lt;/strong&gt; Python module—it’s a third-party library that you must install separately.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You make a GET request&lt;/strong&gt; in Python using &lt;code&gt;requests.get()&lt;/code&gt; with the desired URL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;To add headers to requests&lt;/strong&gt;, pass a dictionary of headers to the &lt;code&gt;headers&lt;/code&gt; parameter in your request.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;To send POST data&lt;/strong&gt;, use the &lt;code&gt;data&lt;/code&gt; parameter for form-encoded data or the &lt;code&gt;json&lt;/code&gt; parameter for JSON data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;response.text&lt;/code&gt; gives you a string&lt;/strong&gt; representation of the response content, while &lt;strong&gt;&lt;code&gt;response.content&lt;/code&gt; provides raw bytes&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This tutorial guides you through customizing requests with headers and data, handling responses, authentication, and optimizing performance using sessions and retries.&lt;/p&gt;
&lt;p&gt;If you want to explore the code examples that you’ll see in this tutorial, then you can download them here:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-requests-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-requests-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to use Python’s Requests library.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Python&#x27;s Requests Library” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-requests/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe5b2;&quot; alt=&quot;Python’s Requests Library (Guide)&quot; src=&quot;https://files.realpython.com/media/Python-Requests-Library-Tutorial_Watermarked.3c9dfdc7b014.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Python-Requests-Library-Tutorial_Watermarked.3c9dfdc7b014.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-Requests-Library-Tutorial_Watermarked.3c9dfdc7b014.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-Requests-Library-Tutorial_Watermarked.3c9dfdc7b014.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-Requests-Library-Tutorial_Watermarked.3c9dfdc7b014.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-requests/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python&#x27;s Requests Library&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your understanding of the Python Requests library for making HTTP requests and interacting with web services.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;get-started-with-pythons-requests-library&quot;&gt;Get Started With Python’s Requests Library&lt;a class=&quot;headerlink&quot; href=&quot;#get-started-with-pythons-requests-library&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Even though the Requests library is a common staple for many Python developers, it’s not included in Python’s &lt;a href=&quot;/ref/glossary/standard-library/&quot; class=&quot;ref-link&quot;&gt;standard library&lt;/a&gt;. That way, the library can continue to evolve more freely as a self-standing project.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’re looking to make HTTP requests with Python’s standard library only, then &lt;a href=&quot;https://realpython.com/urllib-request/&quot;&gt;Python’s &lt;code&gt;urllib.request&lt;/code&gt;&lt;/a&gt; is a good choice for you.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Since Requests is a third-party library, you need to install it before using it in your code. As a good practice, you should install external packages into a &lt;a href=&quot;https://realpython.com/python-virtual-environments-a-primer/&quot;&gt;virtual environment&lt;/a&gt;, but you may choose to install &lt;code&gt;requests&lt;/code&gt; into your global environment if you plan to use it across multiple projects.&lt;/p&gt;
&lt;p&gt;Whether you’re working in a virtual environment or not, you’ll need to install &lt;code&gt;requests&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;requests
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Once &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;&lt;code&gt;pip&lt;/code&gt;&lt;/a&gt; finishes installing &lt;code&gt;requests&lt;/code&gt;, you can use it in your application. Importing &lt;code&gt;requests&lt;/code&gt; looks like this:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now that you’re all set up, it’s time to begin your journey with Requests. Your first goal will be to make a &lt;code&gt;GET&lt;/code&gt; request.&lt;/p&gt;
&lt;h2 id=&quot;make-a-get-request&quot;&gt;Make a GET Request&lt;a class=&quot;headerlink&quot; href=&quot;#make-a-get-request&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods&quot;&gt;HTTP methods&lt;/a&gt;, such as &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;, specify the action you want to perform when making an HTTP request. In addition to &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;, there are several other common methods that you’ll use later in this tutorial.&lt;/p&gt;
&lt;p&gt;One of the most commonly used HTTP methods is &lt;code&gt;GET&lt;/code&gt;, which retrieves data from a specified resource. To make a &lt;code&gt;GET&lt;/code&gt; request using Requests, you can invoke &lt;code&gt;requests.get()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To try this out, you can make a &lt;code&gt;GET&lt;/code&gt; request to &lt;a href=&quot;https://docs.github.com/en/rest&quot;&gt;GitHub’s REST API&lt;/a&gt; by calling &lt;code&gt;get()&lt;/code&gt; with the following URL:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;https://api.github.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;Response [200]&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Congratulations! You’ve made your first request. Now you’ll dive a little deeper into the response of that request.&lt;/p&gt;
&lt;h2 id=&quot;inspect-the-response&quot;&gt;Inspect the Response&lt;a class=&quot;headerlink&quot; href=&quot;#inspect-the-response&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;Response&lt;/code&gt; is the object that contains the results of your request. Try making that same request again, but this time store the return value in a &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt; so you can get a closer look at its &lt;a href=&quot;/ref/glossary/attribute/&quot; class=&quot;ref-link&quot;&gt;attributes&lt;/a&gt; and behaviors:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;https://api.github.com&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-requests/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-requests/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Exploring Python Closures: Examples and Use Cases</title>
      <id>https://realpython.com/courses/closures-examples-use-cases/</id>
      <link href="https://realpython.com/courses/closures-examples-use-cases/"/>
      <updated>2025-07-22T14:00:00+00:00</updated>
      <summary>Learn about Python closures: function-like objects with extended scope used for decorators, factories, and stateful functions.</summary>
      <content type="html">
        &lt;p&gt;In Python, a closure is typically a function defined inside another function. This inner function grabs the objects defined in its enclosing scope and associates them with the inner function object itself. The resulting combination is called a closure.&lt;/p&gt;
&lt;p&gt;Closures are a common feature in functional programming languages. In Python, closures can be pretty useful because they allow you to create function-based decorators, which are powerful tools.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Learn what &lt;strong&gt;closures&lt;/strong&gt; are and how they work in Python&lt;/li&gt;
&lt;li&gt;Get to know common &lt;strong&gt;use cases&lt;/strong&gt; of closures&lt;/li&gt;
&lt;li&gt;Explore &lt;strong&gt;alternatives&lt;/strong&gt; to closures&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>What Does isinstance() Do in Python?</title>
      <id>https://realpython.com/what-does-isinstance-do-in-python/</id>
      <link href="https://realpython.com/what-does-isinstance-do-in-python/"/>
      <updated>2025-07-21T14:00:00+00:00</updated>
      <summary>Learn what isinstance() does in Python and how to use this built-in function to check an object&#x27;s type. Discover its practical uses along with key limitations.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;isinstance()&lt;/code&gt; function helps you determine if an object is an instance of a specified class or its superclass, aiding in writing cleaner and more robust code. You use it to confirm that function parameters are of the expected types, allowing you to handle type-related issues preemptively. This tutorial explores how &lt;code&gt;isinstance()&lt;/code&gt; works, its use with subclasses, and how it differs from &lt;code&gt;type()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;isinstance()&lt;/code&gt;&lt;/strong&gt; checks if an &lt;strong&gt;object&lt;/strong&gt; is a member of a &lt;strong&gt;class&lt;/strong&gt; or &lt;strong&gt;superclass&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;type()&lt;/code&gt;&lt;/strong&gt; checks an object’s specific class, while &lt;strong&gt;&lt;code&gt;isinstance()&lt;/code&gt;&lt;/strong&gt; considers inheritance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;isinstance()&lt;/code&gt;&lt;/strong&gt; correctly identifies instances of &lt;strong&gt;subclasses&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;There’s an &lt;strong&gt;important difference&lt;/strong&gt; between &lt;code&gt;isinstance()&lt;/code&gt; and &lt;code&gt;type()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Exploring &lt;code&gt;isinstance()&lt;/code&gt; will deepen your understanding of the objects you work with and help you write more robust, error-free code.&lt;/p&gt;
&lt;p&gt;To get the most out of this tutorial, it’s recommended that you have a basic understanding of &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt;. More specifically, you should understand the concepts of &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt;, &lt;a href=&quot;/ref/glossary/object/&quot; class=&quot;ref-link&quot;&gt;objects&lt;/a&gt;—also known as &lt;a href=&quot;/ref/glossary/instance/&quot; class=&quot;ref-link&quot;&gt;instances&lt;/a&gt;—and &lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;inheritance&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For this tutorial, you’ll mostly use the Python &lt;a href=&quot;/ref/glossary/repl/&quot; class=&quot;ref-link&quot;&gt;REPL&lt;/a&gt; and some Python files. You won’t need to install any libraries since everything you’ll need is part of core Python. All the code examples are provided in the downloadable materials, and you can access these by clicking the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/what-does-isinstance-do-in-python-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-what-does-isinstance-do-in-python-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code &lt;/a&gt; that you’ll use to learn about isinstance() in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “What Does isinstance() Do in Python?” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-isinstance/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #fe7e73;&quot; alt=&quot;What Does isinstance() Do in Python?&quot; src=&quot;https://files.realpython.com/media/How-Does-isinstance-Work-in-Python_Watermarked.98828170897b.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/How-Does-isinstance-Work-in-Python_Watermarked.98828170897b.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-Does-isinstance-Work-in-Python_Watermarked.98828170897b.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-Does-isinstance-Work-in-Python_Watermarked.98828170897b.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-Does-isinstance-Work-in-Python_Watermarked.98828170897b.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-isinstance/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;What Does isinstance() Do in Python?&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Take this quiz to learn how Python&#x27;s isinstance() introspection function reveals object classes and why it might not always show what you expect.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;It’s time to start this learning journey, where you’ll discover the nature of the objects you use in your code.&lt;/p&gt;
&lt;h2 id=&quot;why-would-you-use-the-python-isinstance-function&quot;&gt;Why Would You Use the Python &lt;code&gt;isinstance()&lt;/code&gt; Function?&lt;a class=&quot;headerlink&quot; href=&quot;#why-would-you-use-the-python-isinstance-function&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;/ref/builtin-functions/isinstance/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;&lt;code&gt;isinstance()&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; function determines whether an object is an instance of a &lt;a href=&quot;/ref/glossary/class/&quot; class=&quot;ref-link&quot;&gt;class&lt;/a&gt;. It also detects whether the object is an instance of a superclass. To use &lt;code&gt;isinstance()&lt;/code&gt;, you pass it two arguments:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The instance you want to analyze&lt;/li&gt;
&lt;li&gt;The class you want to compare the instance against&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These arguments must only be passed by &lt;a href=&quot;https://realpython.com/python-asterisk-and-slash-special-parameters/#can-you-write-a-function-that-accepts-only-positional-arguments&quot;&gt;position&lt;/a&gt;, not by &lt;a href=&quot;/ref/glossary/kwargs/&quot; class=&quot;ref-link&quot;&gt;keyword&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If the object you pass as the first argument is an instance of the class you pass as the second argument, then &lt;code&gt;isinstance()&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt;. Otherwise, it returns &lt;code&gt;False&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You’ll commonly see the terms &lt;em&gt;object&lt;/em&gt; and &lt;em&gt;instance&lt;/em&gt; used interchangeably. This is perfectly correct, but remembering that an object is an instance of a class can help you see the relationship between the two more clearly.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;When you first start learning Python, you’re told that objects are everywhere. Does this mean that every &lt;a href=&quot;https://realpython.com/python-data-types/#integer-numbers&quot;&gt;integer&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;string&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-list/&quot;&gt;list&lt;/a&gt;, or &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;function&lt;/a&gt; you come across is an object? Yes, it does! In the code below, you’ll analyze some basic data types:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;sphere&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;isinstance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;True&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;isinstance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;True&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;isinstance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You create two variables, &lt;code&gt;shape&lt;/code&gt; and &lt;code&gt;number&lt;/code&gt;, which hold &lt;a href=&quot;/ref/builtin-types/str/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;str&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;/ref/builtin-types/int/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;int&lt;/code&gt;&lt;/a&gt; objects, respectively. You then pass &lt;code&gt;shape&lt;/code&gt; and &lt;code&gt;str&lt;/code&gt; to the first call of &lt;code&gt;isinstance()&lt;/code&gt; to prove this. The &lt;code&gt;isinstance()&lt;/code&gt; function returns &lt;code&gt;True&lt;/code&gt;, showing that &lt;code&gt;&quot;sphere&quot;&lt;/code&gt; is indeed a string.&lt;/p&gt;
&lt;p&gt;Next, you pass &lt;code&gt;number&lt;/code&gt; and &lt;code&gt;int&lt;/code&gt; to the second call to &lt;code&gt;isinstance()&lt;/code&gt;, which also returns &lt;code&gt;True&lt;/code&gt;. This tells you &lt;code&gt;8&lt;/code&gt; is an integer. The third call returns &lt;code&gt;False&lt;/code&gt; because &lt;code&gt;8&lt;/code&gt; isn’t a &lt;a href=&quot;https://realpython.com/python-numbers/#floating-point-numbers&quot;&gt;floating-point number&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Knowing the type of data you’re passing to a function is essential to prevent problems caused by invalid types. While it’s better to avoid passing incorrect data in the first place, using &lt;code&gt;isinstance()&lt;/code&gt; gives you a way to avert any undesirable consequences.&lt;/p&gt;
&lt;p&gt;Take a look at the code below:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;calculate_area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;breadth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;breadth&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calculate_area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;15&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calculate_area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;3&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;33333&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Your function takes two numeric values, multiplies them, and returns the answer. Your function works, but only if you pass it two numbers. If you pass it a number and a string, your code won’t crash, but it won’t do what you expect either.&lt;/p&gt;
&lt;p&gt;The string gets replicated when you pass a string and an integer to the multiplication operator (&lt;code&gt;*&lt;/code&gt;). In this case, the &lt;code&gt;&quot;3&quot;&lt;/code&gt; gets replicated five times to form &lt;code&gt;&quot;33333&quot;&lt;/code&gt;, which probably isn’t the result you expected.&lt;/p&gt;
&lt;p&gt;Things get worse when you pass in two strings:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/what-does-isinstance-do-in-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/what-does-isinstance-do-in-python/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Scope and the LEGB Rule: Resolving Names in Your Code</title>
      <id>https://realpython.com/python-scope-legb-rule/</id>
      <link href="https://realpython.com/python-scope-legb-rule/"/>
      <updated>2025-07-16T14:00:00+00:00</updated>
      <summary>Understanding Python&#x27;s variable scope and the LEGB rule helps you avoid name collisions and unexpected behavior. Learn to manage scope and write better code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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 and errors related to name collisions or referencing the wrong variable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;scope&lt;/strong&gt; in Python defines where a variable is &lt;strong&gt;accessible&lt;/strong&gt;, following the local, enclosing, global, and built-in (LEGB) rule.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;namespace&lt;/strong&gt; is a dictionary that maps names to objects and determines their scope.&lt;/li&gt;
&lt;li&gt;The four scope levels—&lt;strong&gt;local&lt;/strong&gt;, &lt;strong&gt;enclosing&lt;/strong&gt;, &lt;strong&gt;global&lt;/strong&gt;, and &lt;strong&gt;built-in&lt;/strong&gt;—each control variable visibility in a specific context.&lt;/li&gt;
&lt;li&gt;Common scope-related built-in functions include &lt;strong&gt;&lt;code&gt;globals()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;locals()&lt;/code&gt;&lt;/strong&gt;, which provide access to global and local namespaces.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should be familiar with Python concepts like &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/inner-functions-what-are-they-good-for/#closures-and-factory-functions&quot;&gt;inner functions&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-exceptions/&quot;&gt;exception handling&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/list-comprehension-python/&quot;&gt;comprehensions&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-scope-legb-rule-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-scope-legb-rule-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to learn about Python scope and the LEGB rule.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;understanding-the-concept-of-scope&quot;&gt;Understanding the Concept of Scope&lt;a class=&quot;headerlink&quot; href=&quot;#understanding-the-concept-of-scope&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In programming, the &lt;strong&gt;scope&lt;/strong&gt; of a name defines the region of a program where you can unambiguously access that name, which could identify a &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-constants/&quot;&gt;constant&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;function&lt;/a&gt;, &lt;a href=&quot;/ref/glossary/class/&quot; class=&quot;ref-link&quot;&gt;class&lt;/a&gt;, or any other object. In most cases, you’ll only be able to access a name within its own scope or from an inner or nested scope.&lt;/p&gt;
&lt;p&gt;Nearly all programming languages use the concept of scope to avoid name collisions and unpredictable behavior. Most often, you’ll distinguish between two main types of scope:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Global scope:&lt;/strong&gt; Names in this scope are available to all your code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Local scope:&lt;/strong&gt; Names in this scope are only available or visible to the code within the scope.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Scope came about because early programming languages like &lt;a href=&quot;https://en.wikipedia.org/wiki/BASIC&quot;&gt;BASIC&lt;/a&gt; only had &lt;strong&gt;global names&lt;/strong&gt;. With this type of name, any part of the program could modify any variable at any time, making large programs difficult to maintain and debug. To work with global names, you’d need to keep all the code in mind to know what value a given name refers to at any time. This is a major side effect of not having scopes and relying solely on global names.&lt;/p&gt;
&lt;p&gt;Modern languages, like Python, use the concept of variable scoping to avoid this kind of issue. When you use a language that implements scopes, you won’t be able to access all the names in a program from all locations. Instead, your ability to access a name depends on its scope.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In this tutorial, you’ll be using the term &lt;strong&gt;name&lt;/strong&gt; to refer to the &lt;a href=&quot;/ref/glossary/identifier/&quot; class=&quot;ref-link&quot;&gt;identifiers&lt;/a&gt; of variables, constants, functions, classes, or any other object that can be assigned a name.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The names in your programs take on the scope of the code block in which you define them. When you can access a name from somewhere in your code, then the name is &lt;strong&gt;in scope&lt;/strong&gt;. If you can’t access the name, then the name is &lt;strong&gt;out of scope&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;names-and-scopes-in-python&quot;&gt;Names and Scopes in Python&lt;a class=&quot;headerlink&quot; href=&quot;#names-and-scopes-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Because Python is a &lt;a href=&quot;https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language&quot;&gt;dynamically-typed&lt;/a&gt; language, its variables come into existence when you first assign them a value. Similarly, functions and classes are available after you define them using &lt;a href=&quot;https://realpython.com/python-keywords/#the-def-keyword&quot;&gt;&lt;code&gt;def&lt;/code&gt;&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/python-keywords/#the-class-keyword&quot;&gt;&lt;code&gt;class&lt;/code&gt;&lt;/a&gt;, respectively. Finally, &lt;a href=&quot;https://realpython.com/python-modules-packages/&quot;&gt;modules&lt;/a&gt; exist after you import them into your current scope.&lt;/p&gt;
&lt;p&gt;You can create names in Python using any of the following operations:&lt;/p&gt;
&lt;div class=&quot;table-responsive&quot;&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;https://realpython.com/python-assignment-operator/&quot;&gt;Assignment&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;variable = value&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;https://realpython.com/python-import/&quot;&gt;Import&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;import module&lt;/code&gt; or &lt;code&gt;from module import name&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;/ref/glossary/function/&quot; class=&quot;ref-link&quot;&gt;Function&lt;/a&gt; definition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;def func(): pass&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Function &lt;a href=&quot;/ref/glossary/argument/&quot; class=&quot;ref-link&quot;&gt;argument&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;func(value1, value2,..., valueN)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;/ref/glossary/class/&quot; class=&quot;ref-link&quot;&gt;Class&lt;/a&gt; definition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;class DemoClass: pass&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;These are all ways to assign a value to either a variable, constant, function, class, instance, or module. In each case, you end up with a name that has a specific scope. This scope will depend on where in your code you’ve defined the name at hand.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; There’s an important difference between &lt;strong&gt;assignment operations&lt;/strong&gt; and &lt;strong&gt;reference or access operations&lt;/strong&gt;. When you assign a name, you’re either creating that name or making it reference a different object. When you reference a name, you’re retrieving the value that the name points to.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Python uses the location of a name definition to associate it with a particular scope. In other words, the place in which you define a name in your code determines the scope or visibility of that name.&lt;/p&gt;
&lt;p&gt;For example, if you define a name inside a function, then that name will have a &lt;strong&gt;local scope&lt;/strong&gt;. You can only access the name locally within the function implementation. In contrast, if you define a name at the top level of a module, then that name will have a &lt;strong&gt;global scope&lt;/strong&gt;. You’ll be able to access it from anywhere in your code.&lt;/p&gt;
&lt;h3 id=&quot;scope-vs-namespace-in-python&quot;&gt;Scope vs Namespace in Python&lt;a class=&quot;headerlink&quot; href=&quot;#scope-vs-namespace-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The concept of scope is closely related to the concept of &lt;a href=&quot;/ref/glossary/namespace/&quot; class=&quot;ref-link&quot;&gt;namespace&lt;/a&gt;. A scope determines the &lt;strong&gt;visibility&lt;/strong&gt; and &lt;strong&gt;lifetime&lt;/strong&gt; of names, while a namespace provides the &lt;strong&gt;place&lt;/strong&gt; where those names are stored.&lt;/p&gt;
&lt;p&gt;Python implements namespaces as &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionaries&lt;/a&gt; that map names to objects. These dictionaries are the underlying mechanism that Python uses to store names under a specific scope. You can often access them through the &lt;a href=&quot;https://realpython.com/python-dict-attribute/&quot;&gt;&lt;code&gt;.__dict__&lt;/code&gt;&lt;/a&gt; attribute of the owning object.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-scope-legb-rule/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-scope-legb-rule/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Getting Started With marimo Notebooks</title>
      <id>https://realpython.com/courses/getting-started-with-marimo-notebooks/</id>
      <link href="https://realpython.com/courses/getting-started-with-marimo-notebooks/"/>
      <updated>2025-07-15T14:00:00+00:00</updated>
      <summary>Discover how marimo notebook simplifies coding with reactive updates, UI elements, and sandboxing for safe, sharable notebooks.</summary>
      <content type="html">
        &lt;p&gt;&lt;a href=&quot;https://marimo.io&quot;&gt;marimo notebooks&lt;/a&gt; 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&amp;rsquo;s features make it an ideal tool for documenting research and learning activities.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;marimo notebooks&lt;/strong&gt; automatically update dependent cells, ensuring consistent results across your work.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reactivity&lt;/strong&gt; allows marimo to determine the correct running order of cells using a &lt;strong&gt;directed acyclic graph (DAG)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sandboxing&lt;/strong&gt; in marimo creates isolated environments for notebooks, preventing package conflicts and ensuring reproducibility.&lt;/li&gt;
&lt;li&gt;You can add &lt;strong&gt;interactivity&lt;/strong&gt; to marimo notebooks with &lt;strong&gt;UI elements&lt;/strong&gt; like sliders and radio buttons.&lt;/li&gt;
&lt;li&gt;Traditional &lt;strong&gt;linear notebooks&lt;/strong&gt; have inherent flaws, such as hidden state issues, that marimo addresses with its reactive design.&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>How to Debug Common Python Errors</title>
      <id>https://realpython.com/debug-python-errors/</id>
      <link href="https://realpython.com/debug-python-errors/"/>
      <updated>2025-07-14T14:00:00+00:00</updated>
      <summary>Learn how to debug Python errors using tracebacks, print(), breakpoints, and tests. Master the tools you need to fix bugs faster and write better code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python debugging involves identifying and fixing errors in your code using tools like tracebacks, &lt;code&gt;print()&lt;/code&gt; calls, breakpoints, and tests. In this tutorial, you’ll learn how to interpret error messages, use &lt;code&gt;print()&lt;/code&gt; 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.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Debugging&lt;/strong&gt; means identifying, analyzing, and resolving issues in your Python code using systematic approaches.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tracebacks&lt;/strong&gt; are messages that help you pinpoint where errors occur in your code, allowing you to resolve them effectively.&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/strong&gt; helps you track variable values and understand code flow, aiding in error identification.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Breakpoints&lt;/strong&gt; let you pause code execution to inspect and debug specific parts, improving error detection.&lt;/li&gt;
&lt;li&gt;Writing and running &lt;strong&gt;tests&lt;/strong&gt; before or during development aids in catching errors early and ensures code reliability.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding these debugging techniques will empower you to handle Python errors confidently and maintain efficient code.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/debug-python-errors-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-debug-python-errors-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code &lt;/a&gt; that shows you how to debug common Python errors.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “How to Debug Common Python Errors” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/debug-python-errors/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe5b2;&quot; alt=&quot;How to Debug Common Python Errors&quot; src=&quot;https://files.realpython.com/media/How-to-Debug-Common-Python-Errors_Watermarked.d94e1bc54ece.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/How-to-Debug-Common-Python-Errors_Watermarked.d94e1bc54ece.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Debug-Common-Python-Errors_Watermarked.d94e1bc54ece.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Debug-Common-Python-Errors_Watermarked.d94e1bc54ece.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Debug-Common-Python-Errors_Watermarked.d94e1bc54ece.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/debug-python-errors/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;How to Debug Common Python Errors&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Take this quiz to review core Python debugging techniques like reading tracebacks, using print(), and setting breakpoints to find and fix errors.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;how-to-get-started-with-debugging-in-python&quot;&gt;How to Get Started With Debugging in Python&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-get-started-with-debugging-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt; means to unravel what is sometimes hidden. It’s the process of identifying, analyzing, and resolving issues, errors, or bugs in your code.&lt;/p&gt;
&lt;p&gt;At its core, debugging involves systematically examining code to determine the root cause of a problem and implementing fixes to ensure the program functions as intended. Debugging is an essential skill for you to develop.&lt;/p&gt;
&lt;p&gt;Debugging often involves using tools and techniques such as breakpoints, logging, and tests to achieve error-free and optimized performance of your code. In simpler terms, to debug is to dig through your code and error messages in an attempt to find the source of the problem, and then come up with a solution to the problem.&lt;/p&gt;
&lt;p&gt;Say you have the following code:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    &lt;span class=&quot;mr-2&quot; aria-label=&quot;Filename&quot;&gt;&lt;code style=&quot;color: inherit; background: inherit;&quot;&gt;cat.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The code that prints the variable &lt;code&gt;cat&lt;/code&gt; is saved in a file called &lt;code&gt;cat.py&lt;/code&gt;. If you try to run the file, then you’ll get a traceback error saying that it can’t find the definition for the variable named &lt;code&gt;cat&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;cat.py
&lt;span class=&quot;go&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  File &quot;/path_to_your_file/cat.py&quot;, line 1, in &amp;lt;module&amp;gt;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    print(cat)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;          ^^^&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;NameError: name &#x27;cat&#x27; is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When Python encounters an error during execution, it prints a &lt;strong&gt;traceback&lt;/strong&gt;, which is a detailed message that shows where the problem occurred in your code. In this example, the variable named &lt;code&gt;cat&lt;/code&gt; can’t be found because it hasn’t been defined.&lt;/p&gt;
&lt;p&gt;Here’s what each part of this &lt;a href=&quot;https://realpython.com/python-traceback/&quot;&gt;Python traceback&lt;/a&gt; means:&lt;/p&gt;
&lt;div class=&quot;table-responsive&quot;&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Traceback (most recent call last)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A generic message sent by Python to notify you of a problem with your code.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;File &quot;/path_to_your_file/cat.py&quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This points to the file where the error originated.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;line 1, in &amp;lt;module&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tells you the exact line in the file where the error occurred.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;print(cat)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Shows you the line of Python code that caused the error.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NameError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tells you the kind of error it is. In this example, you have a &lt;a href=&quot;/ref/builtin-exceptions/nameerror/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;NameError&lt;/code&gt;&lt;/a&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;name &#x27;cat&#x27; is not defined&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is the specific error message that tells you a bit more about what’s wrong with the piece of code.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;In this example, the &lt;a href=&quot;/ref/glossary/interpreter/&quot; class=&quot;ref-link&quot;&gt;Python interpreter&lt;/a&gt; can’t find any prior definition of the variable &lt;code&gt;cat&lt;/code&gt; and therefore can’t provide a value when you call &lt;code&gt;print(cat)&lt;/code&gt;. This is a common Python error that can happen when you forget to define variables with initial values.&lt;/p&gt;
&lt;p&gt;To fix this error, you’ll need to take a step-by-step approach by reading the error message, identifying the problem, and testing solutions until you find one that works.&lt;/p&gt;
&lt;p&gt;In this case, the solution would be to assign a value to the variable &lt;code&gt;cat&lt;/code&gt; before the print call. Here’s an example:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    &lt;span class=&quot;mr-2&quot; aria-label=&quot;Filename&quot;&gt;&lt;code style=&quot;color: inherit; background: inherit;&quot;&gt;cat.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Siamese&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Notice that the error message disappears when you rerun your program, and the following output is printed:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;cat.py
&lt;span class=&quot;go&quot;&gt;Siamese&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The text string stored in &lt;code&gt;cat&lt;/code&gt; is printed as the code output. With this error resolved, you’re well on your way to quickly debugging errors in Python.  &lt;/p&gt;
&lt;p&gt;In the next sections, you’ll explore other approaches to debugging, but first, you’ll take a closer look at using tracebacks.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/debug-python-errors/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/debug-python-errors/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: How to Debug Common Python Errors</title>
      <id>https://realpython.com/quizzes/debug-python-errors/</id>
      <link href="https://realpython.com/quizzes/debug-python-errors/"/>
      <updated>2025-07-14T12:00:00+00:00</updated>
      <summary>Take this quiz to review core Python debugging techniques like reading tracebacks, using print(), and setting breakpoints to find and fix errors.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/debug-python-errors/&quot;&gt;How to Debug Common Python Errors&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Debugging means identifying, analyzing, and resolving issues in your Python code. You&amp;rsquo;ll revisit reading tracebacks, using &lt;code&gt;print()&lt;/code&gt; for value tracking,
setting breakpoints to pause execution, and writing tests to catch errors. Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #257: Comparing Real-World Python Performance Against Big O</title>
      <id>https://realpython.com/podcasts/rpp/257/</id>
      <link href="https://realpython.com/podcasts/rpp/257/"/>
      <updated>2025-07-11T12:00:00+00:00</updated>
      <summary>How does the performance of an algorithm hold up when you put it into a realistic context? Where might Python code defy Big O notation expectations when using a profiler? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;How does the performance of an algorithm hold up when you put it into a realistic context? Where might Python code defy Big O notation expectations when using a profiler? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>What Is Python&#x27;s __init__.py For?</title>
      <id>https://realpython.com/python-init-py/</id>
      <link href="https://realpython.com/python-init-py/"/>
      <updated>2025-07-09T14:00:00+00:00</updated>
      <summary>Learn to declare packages with Python&#x27;s __init__.py, set package variables, simplify imports, and understand what happens if this module is missing.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s special &lt;code&gt;__init__.py&lt;/code&gt; 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.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A directory &lt;strong&gt;without an &lt;code&gt;__init__.py&lt;/code&gt; file&lt;/strong&gt; becomes a &lt;strong&gt;namespace package&lt;/strong&gt;, which behaves differently from a regular package and may cause slower imports.&lt;/li&gt;
&lt;li&gt;You can use &lt;code&gt;__init__.py&lt;/code&gt; to explicitly define a package’s &lt;strong&gt;public API&lt;/strong&gt; by importing specific modules or functions into the package namespace.&lt;/li&gt;
&lt;li&gt;The Python convention of using &lt;strong&gt;leading underscores&lt;/strong&gt; helps indicate to users which objects are intended as &lt;strong&gt;non-public&lt;/strong&gt;, although this convention can still be bypassed.&lt;/li&gt;
&lt;li&gt;Code inside &lt;code&gt;__init__.py&lt;/code&gt; runs &lt;strong&gt;only once&lt;/strong&gt; during the first import, even if you run the import statement multiple times.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding how to effectively use &lt;code&gt;__init__.py&lt;/code&gt; helps you structure your Python packages in a clear, maintainable way, improving usability and namespace management.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The filename &lt;code&gt;__init__.py&lt;/code&gt; is hard to pronounce. Most people find it easier to call it &lt;em&gt;dunder-init&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You may have seen files named &lt;code&gt;__init__.py&lt;/code&gt; scattered throughout large Python projects and wondered exactly what they do. Or you may have used &lt;code&gt;__init__.py&lt;/code&gt; files yourself without a clear idea of why they’re necessary or how to exploit their features. You might also have noticed that your Python code sometimes works even if you forget to add &lt;code&gt;__init__.py&lt;/code&gt; to your packages.&lt;/p&gt;
&lt;p&gt;So, what is &lt;code&gt;__init__.py&lt;/code&gt; for?&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-init-py-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-init-py-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to use Python’s &lt;code&gt;__init__.py&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “What Is Python&#x27;s __init__.py For?” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-init-py/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #ff7e74;&quot; alt=&quot;What Is Python&#x27;s __init__.py For?&quot; src=&quot;https://files.realpython.com/media/What-is-__init__.py-for_Watermarked.e9b5529f58e3.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/What-is-__init__.py-for_Watermarked.e9b5529f58e3.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/What-is-__init__.py-for_Watermarked.e9b5529f58e3.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/What-is-__init__.py-for_Watermarked.e9b5529f58e3.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/What-is-__init__.py-for_Watermarked.e9b5529f58e3.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-init-py/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;What Is Python&#x27;s __init__.py For?&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your understanding of Python&#x27;s __init__.py files to master how they shape your packages, enhance project structure, and keep your code clean.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;in-short-__init__py-declares-a-folder-as-a-regular-python-package&quot;&gt;In Short: &lt;code&gt;__init__.py&lt;/code&gt; Declares a Folder as a Regular Python Package&lt;a class=&quot;headerlink&quot; href=&quot;#in-short-__init__py-declares-a-folder-as-a-regular-python-package&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The special file &lt;code&gt;__init__.py&lt;/code&gt; serves as a marker to indicate that its containing directory is a regular package. When people talk about a &lt;strong&gt;package&lt;/strong&gt; in Python, they generally mean a regular package. The &lt;code&gt;__init__.py&lt;/code&gt; file is a Python source file, which means that it’s also a module.&lt;/p&gt;
&lt;p&gt;If you want to review the terms &lt;a href=&quot;/ref/glossary/module/&quot; class=&quot;ref-link&quot;&gt;module&lt;/a&gt; and &lt;a href=&quot;/ref/glossary/package/&quot; class=&quot;ref-link&quot;&gt;package&lt;/a&gt; and how they’re used in Python, then expand the collapsible section below:&lt;/p&gt;
&lt;div class=&quot;card mb-3&quot; id=&quot;collapse_carde6730f&quot;&gt;
&lt;div class=&quot;card-header border-0&quot;&gt;
&lt;p class=&quot;m-0&quot;&gt;
    &lt;button class=&quot;btn w-100&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapsee6730f&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapsee6730f&quot; markdown=&quot;1&quot;&gt;&lt;span class=&quot;float-left&quot; markdown=&quot;1&quot;&gt;Module vs Package in Python&lt;/span&gt;&lt;span class=&quot;float-right text-muted&quot;&gt;Show/Hide&lt;/span&gt;&lt;/button&gt;
  &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;collapse js-collapsible-section&quot; data-parent=&quot;#collapse_carde6730f&quot; id=&quot;collapsee6730f&quot;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;p&gt;In Python, the terms &lt;a href=&quot;https://realpython.com/python-modules-packages/&quot;&gt;module and package&lt;/a&gt; both describe units containing code:&lt;/p&gt;
&lt;div class=&quot;table-responsive&quot;&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Module&lt;/th&gt;
&lt;th&gt;Package&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A single Python file containing code&lt;/td&gt;
&lt;td&gt;A directory containing one or more Python modules&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Naming&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The filename without the &lt;code&gt;.py&lt;/code&gt; extension&lt;/td&gt;
&lt;td&gt;The directory name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Contents&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Functions, classes, and variables&lt;/td&gt;
&lt;td&gt;Modules and optionally subpackages&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Organizing small projects, simple code reuse&lt;/td&gt;
&lt;td&gt;Organizing large projects, code reuse&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Importing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Import directly (&lt;code&gt;import module&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Import package or its modules (&lt;code&gt;import package.module&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, modules and packages both help organize Python code, with modules representing single files and packages representing directories that can group multiple modules.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The existence of &lt;code&gt;__init__.py&lt;/code&gt; makes the &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-loader&quot;&gt;Python loader&lt;/a&gt; identify its containing directory as a regular package. This means you can import the whole directory, specific modules within it, or even individual functions, variables, and classes from those modules using the package name.&lt;/p&gt;
&lt;p&gt;You can also import those code objects into other modules, which allows your code to be reused in many flexible ways. You’ll see several examples of this shortly.&lt;/p&gt;
&lt;p&gt;As mentioned, &lt;code&gt;__init__.py&lt;/code&gt; may be an empty file, in which case it serves only to identify a package.&lt;/p&gt;
&lt;h2 id=&quot;what-happens-when-i-add-code-to-__init__py&quot;&gt;What Happens When I Add Code to &lt;code&gt;__init__.py&lt;/code&gt;?&lt;a class=&quot;headerlink&quot; href=&quot;#what-happens-when-i-add-code-to-__init__py&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If &lt;code&gt;__init__.py&lt;/code&gt; does contain code, then that code will be executed when the package is first imported.&lt;/p&gt;
&lt;p&gt;The code in &lt;code&gt;__init__.py&lt;/code&gt; can perform a variety of useful tasks. For example, it can import other modules or packages and define its own functions or data. When a package is imported, all of its own code, along with everything it has itself imported, becomes accessible to the importing module.&lt;/p&gt;
&lt;p&gt;You’ll start with a simple example based on a single package. Here’s the setup:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;tools_project/
│
└── tools/
    └── __init__.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;So, your project is named &lt;code&gt;tools_project&lt;/code&gt;. It has a package named &lt;code&gt;tools&lt;/code&gt;. The &lt;code&gt;tools/__init__.py&lt;/code&gt; file could have been completely empty, but here it contains a few lines of code:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    &lt;span class=&quot;mr-2&quot; aria-label=&quot;Filename&quot;&gt;&lt;code style=&quot;color: inherit; background: inherit;&quot;&gt;tools_project/tools/__init__.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;__version__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;1.0.0&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;magic_number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With those files in place, start a &lt;a href=&quot;/ref/glossary/repl/&quot; class=&quot;ref-link&quot;&gt;REPL&lt;/a&gt; session in the &lt;code&gt;tools_project&lt;/code&gt; directory, and watch what happens when you import and use the &lt;code&gt;tools&lt;/code&gt; package:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;linenos&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;tools&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__version__&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 3&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;&#x27;1.0.0&#x27;&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tools&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;magic_number&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-init-py/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-init-py/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: What Is Python&#x27;s __init__.py For?</title>
      <id>https://realpython.com/quizzes/python-init-py/</id>
      <link href="https://realpython.com/quizzes/python-init-py/"/>
      <updated>2025-07-09T12:00:00+00:00</updated>
      <summary>Test your understanding of Python&#x27;s __init__.py files to master how they shape your packages, enhance project structure, and keep your code clean.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your knowledge of &lt;a href=&quot;https://realpython.com/python-init-py/&quot;&gt;Python&amp;rsquo;s &lt;code&gt;__init__.py&lt;/code&gt; file&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Understanding this file&amp;rsquo;s role will help you create more organized and reusable Python code.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Exploring Protocols in Python</title>
      <id>https://realpython.com/courses/exploring-protocols-python/</id>
      <link href="https://realpython.com/courses/exploring-protocols-python/"/>
      <updated>2025-07-08T14:00:00+00:00</updated>
      <summary>Learn how Python&#x27;s protocols improve your use of type hints and static type checkers in this practical video course.</summary>
      <content type="html">
        &lt;p&gt;In Python, a &lt;strong&gt;protocol&lt;/strong&gt; specifies the methods and attributes that a class must implement to be considered of a given type. Protocols are important in Python&amp;rsquo;s &lt;strong&gt;type hint system&lt;/strong&gt;, which allows for static type checking through external tools, such as &lt;a href=&quot;http://mypy-lang.org/&quot;&gt;mypy&lt;/a&gt;, &lt;a href=&quot;https://github.com/microsoft/pyright&quot;&gt;Pyright&lt;/a&gt;, and &lt;a href=&quot;https://pyre-check.org/&quot;&gt;Pyre&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Before there were protocols, these tools could only check for &lt;strong&gt;nominal subtyping&lt;/strong&gt; based on inheritance. There was no way to check for &lt;strong&gt;structural subtyping&lt;/strong&gt;, which relies on the internal structure of classes. This limitation affected Python&amp;rsquo;s &lt;strong&gt;duck typing&lt;/strong&gt; system, which allows you to use objects without considering their nominal types. Protocols overcome this limitation, making static duck typing possible.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Gain clarity around the use of the term &lt;strong&gt;protocol&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;Learn how &lt;strong&gt;type hints&lt;/strong&gt; facilitate &lt;strong&gt;static type checking&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Learn how protocols allow &lt;strong&gt;static duck typing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Create custom protocols with the &lt;strong&gt;&lt;code&gt;Protocol&lt;/code&gt; class&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Understand the differences between &lt;strong&gt;protocols&lt;/strong&gt; and &lt;strong&gt;abstract base classes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Free-Threaded Python Unleashed and Other Python News for July 2025</title>
      <id>https://realpython.com/python-news-july-2025/</id>
      <link href="https://realpython.com/python-news-july-2025/"/>
      <updated>2025-07-07T14:00:00+00:00</updated>
      <summary>Python 3.14&#x27;s free-threaded interpreter is now officially supported—plus more key updates from the world of Python you don&#x27;t want to miss!</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Last month was a watershed moment for Python. &lt;strong&gt;Python 3.14 beta 3&lt;/strong&gt;, released mid-June, isn’t just another pre-release. It’s the first build in which the long-awaited &lt;strong&gt;free-threaded&lt;/strong&gt; or “no-GIL” variant is &lt;em&gt;officially supported&lt;/em&gt;. That’s right: a no-GIL Python is finally taking shape.&lt;/p&gt;
&lt;p&gt;The interpreter isn’t the only thing making headlines, though.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;&lt;p&gt;&lt;strong&gt;Join Now:&lt;/strong&gt; &lt;a href=&quot;&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-newsletter&quot; data-focus=&quot;false&quot;&gt;Click here to join the Real Python Newsletter&lt;/a&gt; and you&#x27;ll never miss another Python tutorial, course, or news update.&lt;/p&gt;&lt;/div&gt;

&lt;h2 id=&quot;core-python-development&quot;&gt;Core Python Development&lt;a class=&quot;headerlink&quot; href=&quot;#core-python-development&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://realpython.com/cpython-source-code-guide/&quot;&gt;CPython’s&lt;/a&gt; core improved in concurrency and stability last month. The third beta of Python 3.14 now officially supports the &lt;strong&gt;no-GIL&lt;/strong&gt; build for CPython, signaling a new era of multi-core Python. That same release also brought &lt;strong&gt;multiple interpreters&lt;/strong&gt; into the standard library, while earlier in June, the core team rolled out a coordinated batch of security patches across all maintained versions to keep your deployments safe.&lt;/p&gt;
&lt;h3 id=&quot;python-314-beta-3-lands-free-threaded-support&quot;&gt;Python 3.14 Beta 3 Lands Free-Threaded Support&lt;a class=&quot;headerlink&quot; href=&quot;#python-314-beta-3-lands-free-threaded-support&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;On June 17, the release team pushed &lt;a href=&quot;https://www.python.org/downloads/release/python-3140b3/&quot;&gt;Python 3.14.0b3&lt;/a&gt; to the mirrors. What sets this beta apart is the acceptance of &lt;a href=&quot;https://peps.python.org/pep-0779/&quot;&gt;PEP 779&lt;/a&gt;, which promotes the GIL-less build from &lt;em&gt;experimental&lt;/em&gt; to &lt;em&gt;supported&lt;/em&gt;. That single status change means &lt;a href=&quot;https://realpython.com/python-wheels/&quot;&gt;binary wheels&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-continuous-integration/&quot;&gt;continuous integration&lt;/a&gt; images, and even hosting platforms can start treating &lt;a href=&quot;https://realpython.com/python313-free-threading-jit/&quot;&gt;free-threaded Python&lt;/a&gt; as a first-class citizen.&lt;/p&gt;
&lt;p&gt;Why is that a big deal? The &lt;a href=&quot;/ref/glossary/gil/&quot; class=&quot;ref-link&quot;&gt;Global Interpreter Lock (GIL)&lt;/a&gt; has long limited Python’s ability to use multiple CPU cores effectively. With a supported no-GIL build, &lt;a href=&quot;https://realpython.com/learning-paths/data-science-python-core-skills/&quot;&gt;data science&lt;/a&gt; and high-throughput web workloads can reach for true &lt;a href=&quot;https://realpython.com/python-parallel-processing/&quot;&gt;multithreading&lt;/a&gt; without resorting to subprocess orchestration.&lt;/p&gt;
&lt;p&gt;While this is exciting, many caveats remain. Native extensions must be rebuilt, and performance trade-offs still exist. Still, the road to production looks increasingly well paved, and the Python community can start preparing for Phase III, which would make the free-threaded build the default.&lt;/p&gt;
&lt;h3 id=&quot;multiple-interpreters-join-the-standard-library&quot;&gt;Multiple Interpreters Join the Standard Library&lt;a class=&quot;headerlink&quot; href=&quot;#multiple-interpreters-join-the-standard-library&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Beta 3 also finalizes another language proposal with &lt;a href=&quot;https://peps.python.org/pep-0734/&quot;&gt;PEP 734 – Multiple Interpreters in the Stdlib&lt;/a&gt;. This PEP supersedes &lt;a href=&quot;https://peps.python.org/pep-0554/&quot;&gt;PEP 554&lt;/a&gt; and adds &lt;a href=&quot;https://realpython.com/python312-subinterpreters/&quot;&gt;Python subinterpreters&lt;/a&gt; to the standard library via the &lt;code&gt;concurrent.interpreters&lt;/code&gt; module. This addition hoists the ability to run multiple interpreters from the C API up to the standard library, paving the way to making this approach to &lt;a href=&quot;https://realpython.com/python-concurrency/&quot;&gt;concurrency&lt;/a&gt; more popular in the Python ecosystem.&lt;/p&gt;
&lt;p&gt;Together with &lt;a href=&quot;https://realpython.com/python-news-june-2025/#three-accepted-peps-tackle-typing-installation-and-compression&quot;&gt;earlier additions&lt;/a&gt; like &lt;a href=&quot;https://realpython.com/python-t-strings/&quot;&gt;t-string literals&lt;/a&gt;, Python 3.14 is shaping up to be a feature-packed release when it ships this October.&lt;/p&gt;
&lt;h3 id=&quot;coordinated-security-releases-ensure-safety&quot;&gt;Coordinated Security Releases Ensure Safety&lt;a class=&quot;headerlink&quot; href=&quot;#coordinated-security-releases-ensure-safety&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you maintain anything on a Long-Term Support (LTS) Python version, then block off some time to upgrade. Earlier last month, the core team released fixes for multiple tarfile &lt;a href=&quot;https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures&quot;&gt;CVE&lt;/a&gt; identifiers and an &lt;a href=&quot;https://realpython.com/python-ipaddress-module/&quot;&gt;&lt;code&gt;ipaddress&lt;/code&gt;&lt;/a&gt; memory bug across all supported branches: 3.13.4, 3.12.11, 3.11.13, 3.10.18, and 3.9.23. If you think this might affect you, then read the full details on the &lt;a href=&quot;https://blog.python.org/2025/06/python-3134-31211-31113-31018-and-3923.html&quot;&gt;Python Insider blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And—as it sometimes goes in life and software—just a week later, &lt;a href=&quot;https://www.python.org/downloads/release/python-3135/&quot;&gt;Python 3.13.5&lt;/a&gt; shipped to fix regressions introduced by 3.13.4. These included, most notably, a Windows build failure for C extensions and unintended delays when raising &lt;code&gt;TypeError&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-built-in-exceptions/&quot;&gt;exceptions&lt;/a&gt; in &lt;a href=&quot;https://realpython.com/introduction-to-python-generators/&quot;&gt;generators&lt;/a&gt;. If you’re on the 3.13 series, then you can upgrade directly to 3.13.5.&lt;/p&gt;
&lt;h2 id=&quot;library-and-tooling-highlights&quot;&gt;Library and Tooling Highlights&lt;a class=&quot;headerlink&quot; href=&quot;#library-and-tooling-highlights&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;From data science to web development, Python’s ecosystem is keeping pace with the core language’s progress.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-july-2025/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-july-2025/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #256: Solving Problems and Saving Time in Chemistry With Python</title>
      <id>https://realpython.com/podcasts/rpp/256/</id>
      <link href="https://realpython.com/podcasts/rpp/256/"/>
      <updated>2025-07-04T12:00:00+00:00</updated>
      <summary>What motivates someone to learn how to code as a scientist? How do you harness the excitement of solving problems quickly and make the connection to the benefits of coding in your scientific work? This week on the show, we speak with Ben Lear and Christopher Johnson about their book &quot;Coding For Chemists.&quot;</summary>
      <content type="html">
        &lt;p&gt;What motivates someone to learn how to code as a scientist? How do you harness the excitement of solving problems quickly and make the connection to the benefits of coding in your scientific work? This week on the show, we speak with Ben Lear and Christopher Johnson about their book &quot;Coding For Chemists.&quot;&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python 3.14 Preview: Template Strings (T-Strings)</title>
      <id>https://realpython.com/python-t-strings/</id>
      <link href="https://realpython.com/python-t-strings/"/>
      <updated>2025-07-02T14:00:00+00:00</updated>
      <summary>Python 3.14 introduces t-strings: a safer, more flexible alternative to f-strings. Learn how to process templates securely and customize string workflows.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;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 &lt;code&gt;str&lt;/code&gt; object, t-strings resolve to a &lt;code&gt;Template&lt;/code&gt; instance, allowing you to safely process and customize dynamic content.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Python &lt;strong&gt;t-strings&lt;/strong&gt; are a generalization of f-strings, designed to safely handle and process &lt;strong&gt;input values&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;main components&lt;/strong&gt; of a t-string include &lt;strong&gt;static string&lt;/strong&gt; parts and &lt;strong&gt;interpolations&lt;/strong&gt;, which are accessible through the &lt;strong&gt;&lt;code&gt;Template&lt;/code&gt;&lt;/strong&gt; class.&lt;/li&gt;
&lt;li&gt;You process t-strings by iterating over their components, using attributes such as &lt;strong&gt;&lt;code&gt;.strings&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;.interpolations&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;.values&lt;/code&gt;&lt;/strong&gt; for safe and customized handling.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Python t-strings enhance both security and flexibility in string processing tasks. This tutorial will guide you through understanding t-strings, comparing them with f-strings, and exploring their practical use cases in Python programming.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-t-strings-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-t-strings-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to use Python 3.14’s new template strings.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Python 3.14 Preview: Template Strings (T-Strings)” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-t-strings/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe0e6;&quot; alt=&quot;Python 3.14 Preview: Template Strings (T-Strings)&quot; src=&quot;https://files.realpython.com/media/Python-3.14-1-Preview-Template-Strings_Watermarked.1071657a0531.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Python-3.14-1-Preview-Template-Strings_Watermarked.1071657a0531.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-3.14-1-Preview-Template-Strings_Watermarked.1071657a0531.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-3.14-1-Preview-Template-Strings_Watermarked.1071657a0531.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-3.14-1-Preview-Template-Strings_Watermarked.1071657a0531.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-t-strings/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python 3.14 Preview: Template Strings (T-Strings)&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Evaluate your grasp of Python&#x27;s t-strings, which provide a structured and secure way to handle string templates.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;exploring-string-templates-before-python-314&quot;&gt;Exploring String Templates Before Python 3.14&lt;a class=&quot;headerlink&quot; href=&quot;#exploring-string-templates-before-python-314&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Creating string templates that you can populate with specific values dynamically is a common requirement in programming. A &lt;strong&gt;string template&lt;/strong&gt; is a string that contains placeholders—special markers representing variable values—that you can dynamically replace at runtime.&lt;/p&gt;
&lt;p&gt;You’ll often use templates to generate text or structured content by filling these placeholders with actual data. Before Python 3.14, the language provided several tools that allowed you to interpolate and format values in your strings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-modulo-string-formatting/&quot;&gt;string formatting operator (&lt;code&gt;%&lt;/code&gt;)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-string-interpolation/#creating-strings-with-the-strformat-method&quot;&gt;&lt;code&gt;str.format()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-f-strings/&quot;&gt;f-strings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-string-interpolation/#building-templates-with-the-template-class&quot;&gt;&lt;code&gt;string.Template&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-built-in-functions/#formatting-strings-format&quot;&gt;&lt;code&gt;format()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3/library/string.html#string.Formatter.parse&quot;&gt;&lt;code&gt;string.Formatter.parse()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can use all these tools to create and process string templates. Of course, each has its own unique strengths and weaknesses.&lt;/p&gt;
&lt;h3 id=&quot;the-string-formatting-operator&quot;&gt;The String Formatting Operator (&lt;code&gt;%&lt;/code&gt;)&lt;a class=&quot;headerlink&quot; href=&quot;#the-string-formatting-operator&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The string formatting operator (&lt;code&gt;%&lt;/code&gt;), inspired by C’s &lt;a href=&quot;https://en.wikipedia.org/wiki/Printf&quot;&gt;&lt;code&gt;printf()&lt;/code&gt;&lt;/a&gt; syntax, is the oldest string formatting and interpolation tool in Python. Here’s a quick example of how you can use this operator to create and process templates:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;city&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Vancouver&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;52&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;The temperature in &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; is &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%d&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; F.&quot;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;The temperature in Vancouver is 52 F.&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you have two variables containing data. The first contains a string, and the second holds an integer value. Then, you define a string template using the &lt;code&gt;%s&lt;/code&gt; and &lt;code&gt;%d&lt;/code&gt; syntax to define &lt;strong&gt;placeholders&lt;/strong&gt; or &lt;strong&gt;replacement fields&lt;/strong&gt;. The &lt;code&gt;s&lt;/code&gt; means that the first field must be filled with a string, and the &lt;code&gt;d&lt;/code&gt; indicates that the field accepts decimal integer values. These are known as &lt;a href=&quot;https://realpython.com/python-modulo-string-formatting/#convert-values-using-a-conversion-type&quot;&gt;conversion types&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Finally, you use the &lt;code&gt;%&lt;/code&gt; operator to dynamically interpolate the variables’ content into the template and build a new string.&lt;/p&gt;
&lt;p&gt;This operator also allows you to apply formatting rules to the input values. For example, here’s how you can format currency values:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;$&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%.2f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2456.5673&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;$2456.57&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, the template contains the literal dollar sign (&lt;code&gt;$&lt;/code&gt;) to indicate that the formatted value represents a USD amount. The &lt;code&gt;$&lt;/code&gt; character is not part of the formatting syntax itself but part of the output.&lt;/p&gt;
&lt;p&gt;Then, you have a replacement field that starts with the string formatting operator (&lt;code&gt;%&lt;/code&gt;) followed by the string &lt;code&gt;&quot;.2f&quot;&lt;/code&gt;. This string is a &lt;strong&gt;format specifier&lt;/strong&gt; that formats any input number as a floating-point value with a precision of two digits.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To learn more about formatting strings, check out the following tutorials:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-formatted-output/&quot;&gt;A Guide to Modern Python String Formatting Tools&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-string-formatting/&quot;&gt;Python String Formatting: Available Tools and Their Features&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-format-mini-language/&quot;&gt;Python’s Format Mini-Language for Tidy Strings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-modulo-string-formatting/&quot;&gt;Modulo String Formatting in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;You can format a string inline using the &lt;code&gt;%&lt;/code&gt; operator by passing the values directly. This approach combines the template and the data in a single step, but it doesn’t allow you to reuse the template later on:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;$&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%.2f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2456.5673&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;$2456.57&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When you have a complex template, the string formatting operator’s syntax can become cumbersome and hard to read:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-t-strings/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-t-strings/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python 3.14 Preview: Template Strings (T-Strings)</title>
      <id>https://realpython.com/quizzes/python-t-strings/</id>
      <link href="https://realpython.com/quizzes/python-t-strings/"/>
      <updated>2025-07-02T12:00:00+00:00</updated>
      <summary>Evaluate your grasp of Python&#x27;s t-strings, which provide a structured and secure way to handle string templates.</summary>
      <content type="html">
        &lt;p&gt;Evaluate your grasp of &lt;a href=&quot;https://realpython.com/python-t-strings/&quot;&gt;Python&amp;rsquo;s t-strings&lt;/a&gt;, which provide a structured and secure way to handle string templates.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Implementing the Factory Method Pattern in Python</title>
      <id>https://realpython.com/courses/factory-method-pattern/</id>
      <link href="https://realpython.com/courses/factory-method-pattern/"/>
      <updated>2025-07-01T14:00:00+00:00</updated>
      <summary>Learn how to use the Factory Method pattern in Python, when to apply it, how to refactor your code for it, and explore a reusable implementation.</summary>
      <content type="html">
        &lt;p&gt;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 &lt;a href=&quot;https://realpython.com/asins/0201633612/&quot;&gt;Design Patterns: Elements of Reusable Object-Oriented Software&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The book describes design patterns as a core design solution to reoccurring problems in software and classifies each design pattern into &lt;a href=&quot;https://en.wikipedia.org/wiki/Software_design_pattern#Classification_and_list&quot;&gt;categories&lt;/a&gt; according to the nature of the problem. Each pattern is given a name, a problem description, a design solution, and an explanation of the consequences of using it.&lt;/p&gt;
&lt;p&gt;The GoF book describes Factory Method as a creational design pattern. Creational design patterns are related to the creation of objects, and Factory Method is a design pattern that creates objects with a common &lt;a href=&quot;https://realpython.com/python-interface/&quot;&gt;interface&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is a recurrent problem that &lt;strong&gt;makes Factory Method one of the most widely used design patterns&lt;/strong&gt;, and it&amp;rsquo;s very important to understand how it works and know how to apply it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Understand the &lt;strong&gt;components&lt;/strong&gt; of &lt;strong&gt;Factory Method&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Recognize &lt;strong&gt;opportunities&lt;/strong&gt; to use &lt;strong&gt;Factory Method&lt;/strong&gt; in your applications&lt;/li&gt;
&lt;li&gt;Know how to &lt;strong&gt;modify existing code&lt;/strong&gt; and &lt;strong&gt;improve its design&lt;/strong&gt; by using the pattern&lt;/li&gt;
&lt;li&gt;Be able to &lt;strong&gt;identify opportunities&lt;/strong&gt; where &lt;strong&gt;Factory Method&lt;/strong&gt; is the appropriate design pattern&lt;/li&gt;
&lt;li&gt;Know how to choose an &lt;strong&gt;appropriate implementation&lt;/strong&gt; of &lt;strong&gt;Factory Method&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Understand how to &lt;strong&gt;implement a reusable, general purpose solution&lt;/strong&gt; of &lt;strong&gt;Factory Method&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Use TorchAudio to Prepare Audio Data for Deep Learning</title>
      <id>https://realpython.com/python-torchaudio/</id>
      <link href="https://realpython.com/python-torchaudio/"/>
      <updated>2025-06-30T14:00:00+00:00</updated>
      <summary>Learn to prepare audio data for deep learning in Python using TorchAudio. Explore how to load, process, and convert speech to spectrograms with PyTorch tools.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Ever wondered how machine learning models process audio data? How do you handle different audio lengths, convert sound frequencies into learnable patterns, and make sure your model is robust? This tutorial will show you how to handle audio data using TorchAudio, a PyTorch-based toolkit.&lt;/p&gt;
&lt;p&gt;You’ll work with real speech data to learn essential techniques like converting waveforms to spectrograms, standardizing audio lengths, and adding controlled noise to build machine and deep learning models.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;TorchAudio&lt;/strong&gt; processes audio data for deep learning, including tasks like loading datasets and augmenting data with noise.&lt;/li&gt;
&lt;li&gt;You can load audio data in &lt;strong&gt;TorchAudio&lt;/strong&gt; using the &lt;code&gt;torchaudio.load()&lt;/code&gt; function, which returns a waveform tensor and sample rate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TorchAudio normalizes&lt;/strong&gt; audio by default during loading, scaling waveform amplitudes between -1.0 and 1.0.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;spectrogram&lt;/strong&gt; visually represents the frequency spectrum of an audio signal over time, aiding in frequency analysis.&lt;/li&gt;
&lt;li&gt;You can pad and trim audio in &lt;strong&gt;TorchAudio&lt;/strong&gt; using &lt;code&gt;torch.nn.functional.pad()&lt;/code&gt; and sequence slicing for uniform audio lengths.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Dive into the tutorial to explore these concepts and learn how they can be applied to prepare audio data for deep learning tasks using TorchAudio.&lt;/p&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Use TorchAudio to Prepare Audio Data for Deep Learning” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-torchaudio/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe0e6;&quot; alt=&quot;Use TorchAudio to Prepare Audio Data for Deep Learning&quot; src=&quot;https://files.realpython.com/media/Use-TorchAudio-to-Prepare-Audio-Data-for-Deep-Learning_Watermarked.97a0be2f5172.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Use-TorchAudio-to-Prepare-Audio-Data-for-Deep-Learning_Watermarked.97a0be2f5172.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Use-TorchAudio-to-Prepare-Audio-Data-for-Deep-Learning_Watermarked.97a0be2f5172.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Use-TorchAudio-to-Prepare-Audio-Data-for-Deep-Learning_Watermarked.97a0be2f5172.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Use-TorchAudio-to-Prepare-Audio-Data-for-Deep-Learning_Watermarked.97a0be2f5172.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.3b8b6b584339.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-torchaudio/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Use TorchAudio to Prepare Audio Data for Deep Learning&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your grasp of audio fundamentals and working with TorchAudio in Python! You&#x27;ll cover loading audio datasets, transforms, and more.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;learn-essential-technical-terms&quot;&gt;Learn Essential Technical Terms&lt;a class=&quot;headerlink&quot; href=&quot;#learn-essential-technical-terms&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before diving into the technical details of audio processing with TorchAudio, take a moment to review some key terms. They’ll help you grasp the basics of working with audio data.&lt;/p&gt;
&lt;h3 id=&quot;waveform&quot;&gt;Waveform&lt;a class=&quot;headerlink&quot; href=&quot;#waveform&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A waveform is the visual representation of sound as it travels through air over time. When you speak, sing, or play music, you create vibrations that move through the air as waves. These waves can be captured and displayed as a graph showing how the sound’s pressure changes over time. Here’s an example:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/sample-waveform-torchaudio.6e633b1568cf.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/sample-waveform-torchaudio.6e633b1568cf.png&quot; width=&quot;1980&quot; height=&quot;780&quot; srcset=&quot;/cdn-cgi/image/width=495,format=auto/https://files.realpython.com/media/sample-waveform-torchaudio.6e633b1568cf.png 495w, /cdn-cgi/image/width=660,format=auto/https://files.realpython.com/media/sample-waveform-torchaudio.6e633b1568cf.png 660w, /cdn-cgi/image/width=990,format=auto/https://files.realpython.com/media/sample-waveform-torchaudio.6e633b1568cf.png 990w, /cdn-cgi/image/width=1980,format=auto/https://files.realpython.com/media/sample-waveform-torchaudio.6e633b1568cf.png 1980w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;A sample waveform of a 440 HZ wave&quot; data-asset=&quot;6370&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;A Sample Waveform of a 440 Hz Wave&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;This is a waveform of a 440 Hz wave, plotted over a short duration of 10 milliseconds (ms). This is called a &lt;strong&gt;time-domain representation&lt;/strong&gt;, showing how the wave’s amplitude changes over time. This waveform shows the raw signal as it appears in an audio editor. The ups and downs reflect changes in loudness.&lt;/p&gt;
&lt;h3 id=&quot;amplitude&quot;&gt;Amplitude&lt;a class=&quot;headerlink&quot; href=&quot;#amplitude&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Amplitude&lt;/strong&gt; is the strength or intensity of a sound wave—in other words, how loud the sound is to the listener. In the previous image, it’s represented by the height of the wave from its center line.&lt;/p&gt;
&lt;p&gt;A higher amplitude means a louder sound, while a lower amplitude means a quieter sound. When you adjust the volume on your device, you’re actually changing the amplitude of the audio signal. In digital audio, amplitude is typically measured in &lt;a href=&quot;https://en.wikipedia.org/wiki/Decibel&quot;&gt;decibels (dB)&lt;/a&gt; or as a normalized value between -1 and 1.&lt;/p&gt;
&lt;h3 id=&quot;frequency&quot;&gt;Frequency&lt;a class=&quot;headerlink&quot; href=&quot;#frequency&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Frequency&lt;/strong&gt; is how many times a sound wave repeats itself in one second, measured in &lt;a href=&quot;https://en.wikipedia.org/wiki/Hertz&quot;&gt;hertz (Hz)&lt;/a&gt;. For example, a low bass note is a sound wave that repeats slowly, about 50–100 Hz. In contrast, a high-pitched whistle has a wave that repeats much faster, around 2000–3000 Hz.&lt;/p&gt;
&lt;p&gt;In music, different frequencies create different musical notes. For instance, the A&lt;sub&gt;4&lt;/sub&gt; note that musicians use to tune their instruments is exactly 440 Hz. Now, if you were to look at the frequency plot of the 440 Hz waveform from before, here’s what you’d see:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/frequency-domain-torchaudio.59106603f830.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/frequency-domain-torchaudio.59106603f830.png&quot; width=&quot;1980&quot; height=&quot;580&quot; srcset=&quot;/cdn-cgi/image/width=495,format=auto/https://files.realpython.com/media/frequency-domain-torchaudio.59106603f830.png 495w, /cdn-cgi/image/width=660,format=auto/https://files.realpython.com/media/frequency-domain-torchaudio.59106603f830.png 660w, /cdn-cgi/image/width=990,format=auto/https://files.realpython.com/media/frequency-domain-torchaudio.59106603f830.png 990w, /cdn-cgi/image/width=1980,format=auto/https://files.realpython.com/media/frequency-domain-torchaudio.59106603f830.png 1980w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Frequency domain plot of a 440 HZ wave&quot; data-asset=&quot;6371&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;A Frequency Domain Plot of a 440 Hz Wave&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;This plot displays the signal in the &lt;strong&gt;frequency domain&lt;/strong&gt;, which shows how much of each frequency is present in the sound. The distinct peak at 440 Hz indicates that this is the dominant frequency in the signal, which is exactly what you’d expect from a pure tone. While time-domain plots—like the one you saw earlier—reveal how the sound’s amplitude changes over time, frequency-domain plots help you understand which frequencies make up the sound.&lt;/p&gt;
&lt;p&gt;The waveform you just explored was from a 440 Hz wave. You’ll soon see that many examples in audio processing also deal with this mysterious frequency. So, what makes it so special?&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;a href=&quot;https://en.wikipedia.org/wiki/A440_(pitch_standard)&quot;&gt;440 Hz frequency&lt;/a&gt; (A&lt;sub&gt;4&lt;/sub&gt; note) is the international standard pitch reference for tuning instruments. Its clear, single-frequency nature makes it great for audio tasks. These include sampling, frequency analysis, and waveform representation.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now that you understand frequency and how it relates to sound waves, you might be wondering how computers actually capture and store these waves. &lt;/p&gt;
&lt;h3 id=&quot;sampling&quot;&gt;Sampling&lt;a class=&quot;headerlink&quot; href=&quot;#sampling&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When you record sound digitally, you’re taking snapshots of the audio wave many times per second. Each snapshot measures the wave’s amplitude at that instant. This is called sampling. The number of snapshots taken per second is the &lt;strong&gt;sampling rate&lt;/strong&gt;, measured in hertz (Hz).&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-torchaudio/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-torchaudio/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Use TorchAudio to Prepare Audio Data for Deep Learning</title>
      <id>https://realpython.com/quizzes/python-torchaudio/</id>
      <link href="https://realpython.com/quizzes/python-torchaudio/"/>
      <updated>2025-06-30T12:00:00+00:00</updated>
      <summary>Test your grasp of audio fundamentals and working with TorchAudio in Python! You&#x27;ll cover loading audio datasets, transforms, and more.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of audio fundamentals and how to &lt;a href=&quot;https://realpython.com/python-torchaudio/&quot;&gt;Use TorchAudio to Prepare Audio Data for Deep Learning&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll revisit fundamental terminology and how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Install and import TorchAudio&lt;/li&gt;
&lt;li&gt;Load audio waveform datasets&lt;/li&gt;
&lt;li&gt;Apply signal transforms&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Work through these questions to check your knowledge about building audio workflows for machine learning in Python.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #255: Structuring Python Scripts &amp; Exciting Non-LLM Software Trends</title>
      <id>https://realpython.com/podcasts/rpp/255/</id>
      <link href="https://realpython.com/podcasts/rpp/255/"/>
      <updated>2025-06-27T12:00:00+00:00</updated>
      <summary>What goes into crafting an effective Python script? How do you organize your code, manage dependencies with PEP 723, and handle command-line arguments for the best results? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What goes into crafting an effective Python script? How do you organize your code, manage dependencies with PEP 723, and handle command-line arguments for the best results? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: The Python print() Function</title>
      <id>https://realpython.com/quizzes/python-print-guide/</id>
      <link href="https://realpython.com/quizzes/python-print-guide/"/>
      <updated>2025-06-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s built-in print() function, covering how to format output, specify custom separators, and more.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;Your Guide to the Python print() Function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;print()&lt;/code&gt; function outputs objects to the console or a specified file-like stream. You&amp;rsquo;ll practice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Printing multiple values with custom separators&lt;/li&gt;
&lt;li&gt;Changing the end-of-line character&lt;/li&gt;
&lt;li&gt;Redirecting output using the &lt;code&gt;file&lt;/code&gt; parameter&lt;/li&gt;
&lt;li&gt;Forcing immediate output with the &lt;code&gt;flush&lt;/code&gt; parameter&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Work through these questions to reinforce your knowledge of &lt;code&gt;print()&lt;/code&gt;&amp;rsquo;s parameters and best practices for clear, formatted I/O.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Starting With DuckDB and Python</title>
      <id>https://realpython.com/courses/starting-duckdb-python/</id>
      <link href="https://realpython.com/courses/starting-duckdb-python/"/>
      <updated>2025-06-24T14:00:00+00:00</updated>
      <summary>Learn how to use DuckDB in Python to query large datasets with SQL or its Python API, handle files like Parquet or CSV, and integrate with pandas or Polars.</summary>
      <content type="html">
        &lt;p&gt;The DuckDB database provides a seamless way to handle large datasets in Python with Online Analytical Processing (OLAP) optimization. You can create databases, verify data imports, and perform efficient data queries using both SQL and DuckDB&amp;rsquo;s Python API.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can &lt;strong&gt;create a DuckDB database&lt;/strong&gt; by reading data from files like Parquet, CSV, or JSON and saving it to a table.&lt;/li&gt;
&lt;li&gt;You &lt;strong&gt;query a DuckDB database&lt;/strong&gt; using standard SQL syntax within Python by executing queries through a DuckDB connection object.&lt;/li&gt;
&lt;li&gt;You can also use &lt;strong&gt;DuckDB&amp;rsquo;s Python API&lt;/strong&gt;, which uses method chaining for an object-oriented approach to database queries.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrent access in DuckDB&lt;/strong&gt; allows multiple reads but restricts concurrent writes to ensure data integrity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DuckDB integrates with pandas and Polars&lt;/strong&gt; by converting query results into DataFrames using the &lt;code&gt;.df()&lt;/code&gt; or &lt;code&gt;.pl()&lt;/code&gt; methods.&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #254: Scaling Python Web Applications With Kubernetes and Karpenter</title>
      <id>https://realpython.com/podcasts/rpp/254/</id>
      <link href="https://realpython.com/podcasts/rpp/254/"/>
      <updated>2025-06-20T12:00:00+00:00</updated>
      <summary>What goes into scaling a web application today? What are resources for learning and practicing DevOps skills? This week on the show, Calvin Hendryx-Parker is back to discuss the tools and infrastructure for autoscaling web applications with Kubernetes and Karpenter.</summary>
      <content type="html">
        &lt;p&gt;What goes into scaling a web application today? What are resources for learning and practicing DevOps skills? This week on the show, Calvin Hendryx-Parker is back to discuss the tools and infrastructure for autoscaling web applications with Kubernetes and Karpenter.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Project: Build a Word Count Command-Line App</title>
      <id>https://realpython.com/courses/word-count-app-project/</id>
      <link href="https://realpython.com/courses/word-count-app-project/"/>
      <updated>2025-06-18T14:00:00+00:00</updated>
      <summary>A self-paced coding challenge in which you&#x27;ll practice your Python skills by building a clone of the popular word count utility (wc) on Unix.</summary>
      <content type="html">
        &lt;p&gt;The &lt;strong&gt;word count&lt;/strong&gt; command (&lt;a href=&quot;https://en.wikipedia.org/wiki/Wc_(Unix)&quot;&gt;&lt;code&gt;wc&lt;/code&gt;&lt;/a&gt;) is a classic utility that you might use to determine the number of lines, words, and bytes in files or &lt;a href=&quot;https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)&quot;&gt;standard input&lt;/a&gt;. It&amp;rsquo;s a staple tool for anyone working with text files on &lt;a href=&quot;https://en.wikipedia.org/wiki/Unix-like&quot;&gt;Unix-like&lt;/a&gt; systems. But have you ever wondered how such a tool is designed and implemented?&lt;/p&gt;
&lt;p&gt;In this practice exercise, you&amp;rsquo;ll dive into the inner workings of the Unix &lt;code&gt;wc&lt;/code&gt; command by building its simplified version from scratch using Python. Not only will this coding challenge solidify your understanding of &lt;a href=&quot;https://realpython.com/working-with-files-in-python/&quot;&gt;file handling&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-string-split-concatenate-join/&quot;&gt;text processing&lt;/a&gt;, but it&amp;rsquo;ll also give you a taste of how to structure &lt;a href=&quot;https://realpython.com/python-command-line-arguments/&quot;&gt;command-line utilities&lt;/a&gt; in Python.&lt;/p&gt;
&lt;p&gt;By the end of this challenge, you&amp;rsquo;ll have a functional version of the &lt;code&gt;wc&lt;/code&gt; command that can faithfully reproduce the outputs you&amp;rsquo;re accustomed to seeing in a Unix &lt;a href=&quot;https://realpython.com/terminal-commands/&quot;&gt;terminal&lt;/a&gt;. However, it won&amp;rsquo;t be an exact replica of the &lt;code&gt;wc&lt;/code&gt; command, as you&amp;rsquo;ll omit or adapt some features for simplicity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this coding challenge, you&amp;rsquo;ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read content from &lt;strong&gt;files&lt;/strong&gt; and &lt;strong&gt;standard input (stdin)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Count the number of &lt;strong&gt;lines&lt;/strong&gt;, &lt;strong&gt;words&lt;/strong&gt;, and &lt;strong&gt;bytes&lt;/strong&gt; in the input&lt;/li&gt;
&lt;li&gt;Differentiate between bytes and &lt;strong&gt;characters&lt;/strong&gt; to handle &lt;strong&gt;Unicode&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Implement &lt;strong&gt;command-line arguments&lt;/strong&gt; to specify what counts to display&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While working on this challenge, you&amp;rsquo;ll gain hands-on experience with several modules from Python&amp;rsquo;s standard library, such as &lt;a href=&quot;https://realpython.com/python-pathlib/&quot;&gt;&lt;code&gt;pathlib&lt;/code&gt;&lt;/a&gt; for manipulating the file system and &lt;a href=&quot;https://realpython.com/command-line-interfaces-python-argparse/&quot;&gt;&lt;code&gt;argparse&lt;/code&gt;&lt;/a&gt; for parsing command-line arguments. Familiarity with basic Python programming and file handling will be beneficial, but detailed instructions and helpful tips will guide you through each step of the process.&lt;/p&gt;
&lt;p&gt;The challenge is broken down into a number of &lt;strong&gt;tasks&lt;/strong&gt;, each accompanied by clear instructions and illustrative examples. You&amp;rsquo;ll receive &lt;strong&gt;automated feedback&lt;/strong&gt; on your solutions when you follow along using the accompanying materials. If you run into any issues or have questions, then don&amp;rsquo;t hesitate to ask for help in the &lt;strong&gt;comments section&lt;/strong&gt; below the corresponding lesson.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can also reach out to the Real Python community on &lt;a href=&quot;https://realpython.com/community/&quot;&gt;Slack&lt;/a&gt; or join live conversations during &lt;a href=&quot;https://realpython.com/office-hours/&quot;&gt;Office Hours&lt;/a&gt;, where you&amp;rsquo;ll have an opportunity to share your screen remotely.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Completing each task unlocks the next one. Once you&amp;rsquo;ve completed a task, you can compare your code with the &lt;strong&gt;sample solution&lt;/strong&gt; provided in the following lesson. Remember that there&amp;rsquo;s often more than one way to solve a problem. If your solution differs slightly but meets the acceptance criteria and adheres to good programming practices, then that&amp;rsquo;s perfectly fine.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Exploring Python&#x27;s list Data Type With Examples</title>
      <id>https://realpython.com/courses/list-data-type-with-examples/</id>
      <link href="https://realpython.com/courses/list-data-type-with-examples/"/>
      <updated>2025-06-17T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll dive deep into Python&#x27;s lists: how to create them, update their content, populate and grow them - with practical code examples.</summary>
      <content type="html">
        &lt;p&gt;The &lt;strong&gt;&lt;code&gt;list&lt;/code&gt;&lt;/strong&gt; class is a fundamental &lt;strong&gt;built-in data type&lt;/strong&gt; in Python. It has an impressive and useful set of features, allowing you to efficiently organize and manipulate heterogeneous data. Knowing how to use lists is a must-have skill for you as a Python developer. Lists have many use cases, so you&amp;rsquo;ll frequently reach for them in real-world coding.&lt;/p&gt;
&lt;p&gt;By working through this video course, you&amp;rsquo;ll dive deep into lists and get a solid understanding of their key features. This knowledge will allow you to write more effective code by taking advantage of lists.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Create&lt;/strong&gt; new lists in Python&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access&lt;/strong&gt; the items in an existing list&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Copy&lt;/strong&gt;, &lt;strong&gt;update&lt;/strong&gt;, &lt;strong&gt;grow&lt;/strong&gt;, &lt;strong&gt;shrink&lt;/strong&gt;, and &lt;strong&gt;concatenate&lt;/strong&gt; existing lists&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sort&lt;/strong&gt;, &lt;strong&gt;reverse&lt;/strong&gt;, and &lt;strong&gt;traverse&lt;/strong&gt; existing lists&lt;/li&gt;
&lt;li&gt;Use other &lt;strong&gt;features&lt;/strong&gt; of Python lists&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #253: Starting With marimo Notebooks &amp; Python App Config Management</title>
      <id>https://realpython.com/podcasts/rpp/253/</id>
      <link href="https://realpython.com/podcasts/rpp/253/"/>
      <updated>2025-06-13T12:00:00+00:00</updated>
      <summary>Looking for a guide on getting started with marimo notebooks? How do you build a reproducible notebook for sharing or create a dashboard with interactive UI elements? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;Looking for a guide on getting started with marimo notebooks? How do you build a reproducible notebook for sharing or create a dashboard with interactive UI elements? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Defining Your Own Python Function</title>
      <id>https://realpython.com/quizzes/python-function/</id>
      <link href="https://realpython.com/quizzes/python-function/"/>
      <updated>2025-06-11T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of defining and calling Python functions. You&#x27;ll revisit the def keyword, parameters, arguments, and more.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;Defining Your Own Python Function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll revisit how to define a function with the &lt;code&gt;def&lt;/code&gt; keyword, specify parameters, pass arguments, and call your functions to make code modular and reusable. You&amp;rsquo;ll also see how functions help organize and maintain your Python projects.&lt;/p&gt;
&lt;p&gt;Ready to demonstrate your skills? Let&amp;rsquo;s begin!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Continuous Integration and Deployment Using GitHub Actions</title>
      <id>https://realpython.com/courses/cicd-github-actions/</id>
      <link href="https://realpython.com/courses/cicd-github-actions/"/>
      <updated>2025-06-10T14:00:00+00:00</updated>
      <summary>Agile methodologies rely on robust DevOps systems to manage and automate common tasks in a continually changing codebase. GitHub Actions can help.</summary>
      <content type="html">
        &lt;p&gt;Creating software is an achievement worth celebrating. But software is never static. Bugs need to be fixed, features need to be added, and security demands regular updates. In today&amp;rsquo;s landscape, with agile methodologies dominating, robust &lt;a href=&quot;https://realpython.com/learning-paths/python-devops/&quot;&gt;DevOps&lt;/a&gt; systems are crucial for managing an evolving codebase. That&amp;rsquo;s where GitHub Actions shine, empowering Python developers to automate workflows and ensure their projects adapt seamlessly to change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub Actions&lt;/strong&gt; for Python empowers developers to automate workflows efficiently. This enables teams to maintain software quality while adapting to constant change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Continuous Integration and Continuous Deployment (CI/CD)&lt;/strong&gt; systems help produce well-tested, high-quality software and streamline deployment. GitHub Actions makes CI/CD accessible to all, allowing automation and customization of workflows directly in your repository. This free service enables developers to execute their software development processes efficiently, improving productivity and code reliability.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;GitHub Actions&lt;/strong&gt; and &lt;strong&gt;workflows&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Automate &lt;strong&gt;linting, testing, and deployment&lt;/strong&gt; of a Python project&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Secure credentials&lt;/strong&gt; used for automation&lt;/li&gt;
&lt;li&gt;Automate &lt;strong&gt;security and dependency updates&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #252: Rodrigo Girão Serrão: Python Training, itertools, and Idioms</title>
      <id>https://realpython.com/podcasts/rpp/252/</id>
      <link href="https://realpython.com/podcasts/rpp/252/"/>
      <updated>2025-06-06T12:00:00+00:00</updated>
      <summary>Once you&#x27;ve learned the vocabulary and syntax of the Python language, how do you progress into learning the right combinations to put into your code? How can Python&#x27;s built-in itertools library enhance your skills? This week on the show, we speak with Rodrigo Girão Serrão about teaching Python through his blog and his passion for the itertools library.</summary>
      <content type="html">
        &lt;p&gt;Once you&#x27;ve learned the vocabulary and syntax of the Python language, how do you progress into learning the right combinations to put into your code? How can Python&#x27;s built-in itertools library enhance your skills? This week on the show, we speak with Rodrigo Girão Serrão about teaching Python through his blog and his passion for the itertools library.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: How to Find an Absolute Value in Python</title>
      <id>https://realpython.com/quizzes/python-absolute-value/</id>
      <link href="https://realpython.com/quizzes/python-absolute-value/"/>
      <updated>2025-06-04T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your knowledge of calculating absolute values in Python, mastering both built-in functions and common use cases to improve your coding accuracy.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/python-absolute-value/&quot;&gt;How to Find an Absolute Value in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit key concepts such as how to use Python&amp;rsquo;s built-in functions to compute absolute values, apply them in mathematical operations, and handle different data types effectively.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Execute Your Python Scripts With a Shebang</title>
      <id>https://realpython.com/courses/execute-python-scripts-with-shebang/</id>
      <link href="https://realpython.com/courses/execute-python-scripts-with-shebang/"/>
      <updated>2025-06-03T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn when and how to use the shebang line in your Python scripts to execute them from a Unix-like shell.</summary>
      <content type="html">
        &lt;p&gt;In shell scripts, the shebang line (&lt;code&gt;#!&lt;/code&gt;) specifies the path to the interpreter that should execute the file. You can place it at the top of your Python file to tell the shell how to run your script, allowing you to execute the script directly without typing &lt;code&gt;python&lt;/code&gt; before the script name. The shebang is essential for Unix-like systems but ignored on Windows unless using specific compatibility layers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A shebang &lt;strong&gt;specifies the path to the Python interpreter&lt;/strong&gt; in scripts, allowing direct execution.&lt;/li&gt;
&lt;li&gt;You should &lt;strong&gt;include a shebang when a script needs direct execution&lt;/strong&gt;, but not in import-only modules.&lt;/li&gt;
&lt;li&gt;Best practices for shebangs include &lt;strong&gt;using &lt;code&gt;/usr/bin/env&lt;/code&gt; for portability&lt;/strong&gt; and ensuring the script is executable.&lt;/li&gt;
&lt;li&gt;Shebangs have limitations, such as being &lt;strong&gt;ignored on Windows&lt;/strong&gt; without compatibility layers like WSL.&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: How Can You Structure Your Python Script?</title>
      <id>https://realpython.com/quizzes/python-script-structure/</id>
      <link href="https://realpython.com/quizzes/python-script-structure/"/>
      <updated>2025-06-01T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of organizing and structuring Python scripts. You&#x27;ll revisit key concepts about best practices for writing clear, maintainable, and executable Python code.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the tutorial &lt;a href=&quot;https://realpython.com/python-script-structure/&quot;&gt;How Can You Structure Your Python Script?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit best practices for organizing your Python scripts, including setting up the main entry point, using imports effectively, and writing code that can be reused as modules or run as standalone scripts.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #251: Python Thread Safety &amp; Managing Projects With uv</title>
      <id>https://realpython.com/podcasts/rpp/251/</id>
      <link href="https://realpython.com/podcasts/rpp/251/"/>
      <updated>2025-05-30T12:00:00+00:00</updated>
      <summary>What are the ways you can manage multithreaded code in Python? What synchronization techniques are available within Python&#x27;s threading module? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the ways you can manage multithreaded code in Python? What synchronization techniques are available within Python&#x27;s threading module? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Control Flow Structures in Python</title>
      <id>https://realpython.com/quizzes/python-control-flow/</id>
      <link href="https://realpython.com/quizzes/python-control-flow/"/>
      <updated>2025-05-28T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python control flow structures, which include conditionals, loops, exception handling, and structural pattern matching. Strengthening these skills will help you write more dynamic, smart, and robust Python code.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of control flow structures in Python. Control flow dictates the order in which your code executes, letting you make choices, repeat work, and handle exceptions to build more flexible, reliable programs. For hands-on examples and a deeper dive, check out the tutorial &lt;a href=&quot;https://realpython.com/python-control-flow/&quot;&gt;Control Flow Structures in Python&lt;/a&gt;.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #250: DjangoCon Europe 2025: Live Recording From Dublin</title>
      <id>https://realpython.com/podcasts/rpp/250/</id>
      <link href="https://realpython.com/podcasts/rpp/250/"/>
      <updated>2025-05-23T12:00:00+00:00</updated>
      <summary>What goes into making video courses at Real Python? How should you build an installable Django application? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What goes into making video courses at Real Python? How should you build an installable Django application? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #249: Going Beyond requirements.txt With pylock.toml and PEP 751</title>
      <id>https://realpython.com/podcasts/rpp/249/</id>
      <link href="https://realpython.com/podcasts/rpp/249/"/>
      <updated>2025-05-16T12:00:00+00:00</updated>
      <summary>What is the best way to record the Python dependencies for the reproducibility of your projects? What advantages will lock files provide for those projects? This week on the show, we welcome back Python Core Developer Brett Cannon to discuss his journey to bring PEP 751 and the pylock.toml file format to the community.</summary>
      <content type="html">
        &lt;p&gt;What is the best way to record the Python dependencies for the reproducibility of your projects? What advantages will lock files provide for those projects? This week on the show, we welcome back Python Core Developer Brett Cannon to discuss his journey to bring PEP 751 and the pylock.toml file format to the community.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  

</feed>
