<?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-08-29T12:00:00+00:00</updated>
  <id>https://realpython.com/</id>
  <author>
    <name>Real Python</name>
  </author>

  
    <entry>
      <title>The Real Python Podcast – Episode #263: Exploring Mixin Classes in Python</title>
      <id>https://realpython.com/podcasts/rpp/263/</id>
      <link href="https://realpython.com/podcasts/rpp/263/"/>
      <updated>2025-08-29T12:00:00+00:00</updated>
      <summary>What is a good way to add isolated, reusable functionality to Python classes? 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 is a good way to add isolated, reusable functionality to Python classes? 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: Exploring Python Closures: Examples and Use Cases</title>
      <id>https://realpython.com/quizzes/closures-examples-use-cases/</id>
      <link href="https://realpython.com/quizzes/closures-examples-use-cases/"/>
      <updated>2025-08-29T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python closures. Closures are a common feature in functional programming languages and are particularly popular in Python because they allow you to create function-based decorators.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of Python closures. Closures are a common feature in functional programming languages and are particularly popular in Python because they allow you to create function-based decorators.&lt;/p&gt;
&lt;p&gt;Take this quiz after taking our &lt;a href=&quot;https://realpython.com/courses/closures-examples-use-cases/&quot;&gt;Exploring Python Closures: Examples and Use Cases&lt;/a&gt; course.&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: Deep vs Shallow Copies in Python</title>
      <id>https://realpython.com/quizzes/deep-vs-shallow-copies/</id>
      <link href="https://realpython.com/quizzes/deep-vs-shallow-copies/"/>
      <updated>2025-08-29T12:00:00+00:00</updated>
      <summary>Test your understanding of deep and shallow copying in Python. Review assignment, identity, and how to copy complex objects correctly.</summary>
      <content type="html">
        &lt;p&gt;Ready to reinforce your knowledge of deep and shallow copies in Python? This quiz covers assignment semantics, object identity, and how to properly copy nested and user-defined objects. You will also practice writing your own copy helpers and customizing class copying.&lt;/p&gt;
&lt;p&gt;Brush up on these essential concepts before you start by reviewing &lt;a href=&quot;https://realpython.com/courses/deep-vs-shallow-copies/&quot;&gt;Deep vs Shallow Copies 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>Quiz: Exploring Python T-Strings</title>
      <id>https://realpython.com/quizzes/exploring-t-strings/</id>
      <link href="https://realpython.com/quizzes/exploring-t-strings/"/>
      <updated>2025-08-28T12:00:00+00:00</updated>
      <summary>Explore Python&#x27;s t-strings, including their syntax, use cases, and differences from f-strings and older approaches.</summary>
      <content type="html">
        &lt;p&gt;Ready to brush up on Python&amp;rsquo;s powerful string formatting tools? This quiz walks you through the essential techniques, including f-strings, C-style formatting, and &lt;code&gt;str.format()&lt;/code&gt;. You&amp;rsquo;ll also get hands-on with a newer feature in Python 3.14: t-strings.&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: Profiling Performance in Python</title>
      <id>https://realpython.com/quizzes/profiling-performance/</id>
      <link href="https://realpython.com/quizzes/profiling-performance/"/>
      <updated>2025-08-28T12:00:00+00:00</updated>
      <summary>Test your knowledge of Python profiling and performance tools. Practice identifying bottlenecks and using profilers like cProfile and timeit.</summary>
      <content type="html">
        &lt;p&gt;Ready to level up your Python code optimization skills? In this quiz, you&amp;rsquo;ll revisit key concepts about profiling, benchmarking, and diagnosing performance bottlenecks. You&amp;rsquo;ll practice with tools like cProfile and timeit, and see how deterministic and statistical profilers differ.&lt;/p&gt;
&lt;p&gt;Brush up on the profiling workflow and see how to spot hotspots efficiently in your programs. Need a refresher? Check out the &lt;a href=&quot;https://realpython.com/courses/profiling-performance/&quot;&gt;Profiling Performance in Python&lt;/a&gt; for detailed guidance.&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: Lazy Annotations</title>
      <id>https://realpython.com/python-annotations/</id>
      <link href="https://realpython.com/python-annotations/"/>
      <updated>2025-08-27T14:00:00+00:00</updated>
      <summary>Explore how Python 3.14&#x27;s lazy evaluation of annotations boosts performance, fixes chronic type hinting issues, and unlocks powerful new runtime uses.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Recent Python releases have introduced several small improvements to the type hinting system, but Python 3.14 brings a single major change: lazy annotations. This change delays annotation evaluation until explicitly requested, improving performance and resolving issues with forward references. Library maintainers might need to adapt, but for regular Python users, this change promises a simpler and faster development experience.&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;Although &lt;strong&gt;annotations&lt;/strong&gt; are used primarily for &lt;strong&gt;type hinting&lt;/strong&gt; in Python, they support both static type checking and runtime metadata processing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lazy annotations&lt;/strong&gt; in Python 3.14 defer evaluation until needed, enhancing performance and reducing startup time.&lt;/li&gt;
&lt;li&gt;Lazy annotations address issues with &lt;strong&gt;forward references&lt;/strong&gt;, allowing types to be defined later.&lt;/li&gt;
&lt;li&gt;You can access annotations via the &lt;strong&gt;&lt;code&gt;.__annotations__&lt;/code&gt;&lt;/strong&gt; attribute or use &lt;strong&gt;&lt;code&gt;annotationlib.get_annotations()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;typing.get_type_hints()&lt;/code&gt;&lt;/strong&gt; for more robust introspection.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;typing.Annotated&lt;/code&gt;&lt;/strong&gt; enables combining type hints with metadata, facilitating both static type checking and runtime processing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Explore how lazy annotations in Python 3.14 streamline your development process, offering both performance benefits and enhanced code clarity. If you’re just looking for a brief overview of the key changes in 3.14, then expand the collapsible section below:&lt;/p&gt;
&lt;div class=&quot;card mb-3&quot; id=&quot;collapse_card681068&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;#collapse681068&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapse681068&quot; markdown=&quot;1&quot;&gt;&lt;span class=&quot;float-left&quot; markdown=&quot;1&quot;&gt;What&#x27;s New in Python 3.14: A Quick Summary&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_card681068&quot; id=&quot;collapse681068&quot;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;p&gt;Python 3.14 introduces &lt;strong&gt;lazy evaluation of annotations&lt;/strong&gt;, solving long-standing pain points with type hints. Here’s what you need to know:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Annotations are no longer evaluated at definition time. Instead, their processing is deferred until you explicitly access them.&lt;/li&gt;
&lt;li&gt;Forward references work out of the box without needing string literals or &lt;code&gt;from __future__ import annotations&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Circular imports are no longer an issue for type hints because annotations don’t trigger immediate name resolution.&lt;/li&gt;
&lt;li&gt;Startup performance improves, especially for modules with expensive annotation expressions.&lt;/li&gt;
&lt;li&gt;Standard tools, such as &lt;code&gt;typing.get_type_hints()&lt;/code&gt; and &lt;code&gt;inspect.get_annotations()&lt;/code&gt;, still work but now benefit from the new evaluation strategy.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;inspect.get_annotations()&lt;/code&gt; becomes deprecated in favor of the enhanced &lt;code&gt;annotationlib.get_annotations()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You can now request annotations at runtime in alternative formats, including strings, values, and proxy objects that safely handle forward references.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These changes make type hinting faster, safer, and easier to use, mostly without breaking backward compatibility.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&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-annotations-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-annotations-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 lazy annotations in Python 3.14.&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.770597e4ea96.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 Annotations” 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-annotations/&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;Python 3.14 Preview: Lazy Annotations&quot; src=&quot;https://files.realpython.com/media/Python-3.14-Preview-Lazy-Annotations-PEP-649.aae06a71abf4.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-Preview-Lazy-Annotations-PEP-649.aae06a71abf4.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-3.14-Preview-Lazy-Annotations-PEP-649.aae06a71abf4.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-3.14-Preview-Lazy-Annotations-PEP-649.aae06a71abf4.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-3.14-Preview-Lazy-Annotations-PEP-649.aae06a71abf4.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.770597e4ea96.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-annotations/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python Annotations&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your knowledge of annotations and type hints, including how different Python versions evaluate them at runtime.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;python-annotations-in-a-nutshell&quot;&gt;Python Annotations in a Nutshell&lt;a class=&quot;headerlink&quot; href=&quot;#python-annotations-in-a-nutshell&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before diving into what’s changed in &lt;strong&gt;Python 3.14&lt;/strong&gt; regarding annotations, it’s a good idea to review some of the terminology surrounding annotations. In the next sections, you’ll learn the difference between annotations and type hints, and review some of their most common use cases. If you’re already familiar with these concepts, then skip straight to &lt;a href=&quot;#lazy-evaluation-of-annotations-in-python-314&quot;&gt;lazy evaluation of annotations&lt;/a&gt; for details on how the new annotation processing works.&lt;/p&gt;
&lt;h3 id=&quot;annotations-vs-type-hints&quot;&gt;Annotations vs Type Hints&lt;a class=&quot;headerlink&quot; href=&quot;#annotations-vs-type-hints&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Arguably, &lt;a href=&quot;/ref/glossary/type-hint/&quot; class=&quot;ref-link&quot;&gt;type hints&lt;/a&gt; are the most common use case for &lt;a href=&quot;/ref/glossary/annotation/&quot; class=&quot;ref-link&quot;&gt;annotations&lt;/a&gt; in Python today. However, annotations are a more general-purpose feature with broader applications. They’re a form of syntactic &lt;a href=&quot;https://en.wikipedia.org/wiki/Metadata&quot;&gt;metadata&lt;/a&gt; that you can optionally attach to your Python &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Although annotations can convey arbitrary information, they must follow the language’s syntax rules. In other words, you won’t be able to define an annotation representing a piece of syntactically incorrect Python code.&lt;/p&gt;
&lt;p&gt;To be even more precise, annotations must be valid Python &lt;a href=&quot;/ref/glossary/expression/&quot; class=&quot;ref-link&quot;&gt;expressions&lt;/a&gt;, such as string literals, arithmetic operations, or even function calls. On the other hand, annotations can’t be simple or compound &lt;a href=&quot;/ref/glossary/statement/&quot; class=&quot;ref-link&quot;&gt;statements&lt;/a&gt; that aren’t expressions, like &lt;a href=&quot;https://realpython.com/python-assignment-operator/&quot;&gt;assignments&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;conditionals&lt;/a&gt;, because those might have unintended &lt;a href=&quot;https://en.wikipedia.org/wiki/Side_effect_(computer_science)&quot;&gt;side effects&lt;/a&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; For a deeper explanation of the difference between these two constructs, check out &lt;a href=&quot;https://realpython.com/python-expression-vs-statement/&quot;&gt;Expression vs Statement in Python: What’s the Difference?&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Python supports two flavors of annotations, as specified in &lt;a href=&quot;https://peps.python.org/pep-3107/&quot;&gt;PEP 3107&lt;/a&gt; and &lt;a href=&quot;https://peps.python.org/pep-0526/&quot;&gt;PEP 526&lt;/a&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Function annotations:&lt;/strong&gt; Metadata attached to signatures of &lt;a href=&quot;/ref/glossary/callable/&quot; class=&quot;ref-link&quot;&gt;callable objects&lt;/a&gt;, including functions and &lt;a href=&quot;https://realpython.com/instance-class-and-static-methods-demystified/&quot;&gt;methods&lt;/a&gt;—but not &lt;a href=&quot;https://realpython.com/python-lambda/&quot;&gt;lambda functions&lt;/a&gt;, which don’t support the annotation syntax.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Variable annotations:&lt;/strong&gt; Metadata attached to local, &lt;a href=&quot;/ref/keywords/nonlocal/&quot; class=&quot;ref-link&quot;&gt;nonlocal&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-use-global-variable-in-function/&quot;&gt;global variables&lt;/a&gt;, as well as class and instance &lt;a href=&quot;/ref/glossary/attribute/&quot; class=&quot;ref-link&quot;&gt;attributes&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The syntax for function and variable annotations looks almost identical, except that functions support additional notation for specifying their &lt;a href=&quot;https://realpython.com/python-return-statement/&quot;&gt;return value&lt;/a&gt;. Below is the official syntax for both types of annotations in Python. Note that &lt;code&gt;&amp;lt;annotation&amp;gt;&lt;/code&gt; is a placeholder, and you don’t need the angle brackets when replacing this placeholder with the actual annotation:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python_syntax&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 Syntax&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;Python 3.6+&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;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# These two could be either class or instance attributes:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;attribute1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;attribute2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&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;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parameter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parameter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parameter3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;default_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parameter4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;default_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;instance_attribute1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;instance_attribute2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;
        &lt;span class=&quot;o&quot;&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;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parameter1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parameter2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parameter3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;default_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;parameter4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;default_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;variable1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;variable2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;annotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&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.770597e4ea96.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.770597e4ea96.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;To annotate a variable, attribute, or function parameter, put a colon (&lt;code&gt;:&lt;/code&gt;) just after its name, followed by the annotation itself. Conversely, to annotate a function’s return value, place the right arrow (&lt;code&gt;-&amp;gt;&lt;/code&gt;) symbol after the closing parenthesis of the parameter list. The return annotation goes between that arrow and the colon denoting the start of the function’s body. &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 right arrow symbol isn’t unique to Python. A few other programming languages use it as well but for different purposes. For example, &lt;a href=&quot;https://realpython.com/java-vs-python/&quot;&gt;Java&lt;/a&gt; and &lt;a href=&quot;https://coffeescript.org/&quot;&gt;CoffeeScript&lt;/a&gt; use it to define anonymous functions, similar to Python’s lambdas. This symbol is sometimes referred to as the &lt;em&gt;thin&lt;/em&gt; arrow (&lt;code&gt;-&amp;gt;&lt;/code&gt;) to distinguish it from the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fat_comma&quot;&gt;fat arrow (&lt;code&gt;=&amp;gt;&lt;/code&gt;)&lt;/a&gt; found in &lt;a href=&quot;https://realpython.com/python-vs-javascript/&quot;&gt;JavaScript&lt;/a&gt; and &lt;a href=&quot;https://www.scala-lang.org/&quot;&gt;Scala&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As shown, you can mix and match function and method parameters, including &lt;a href=&quot;https://realpython.com/python-optional-arguments/&quot;&gt;optional parameters&lt;/a&gt;, with or without annotations. You can also annotate a variable without assigning it a value, effectively making a &lt;a href=&quot;https://en.wikipedia.org/wiki/Declaration_(computer_programming)&quot;&gt;declaration&lt;/a&gt; of an &lt;a href=&quot;/ref/glossary/identifier/&quot; class=&quot;ref-link&quot;&gt;identifier&lt;/a&gt; that might be defined later.&lt;/p&gt;
&lt;p&gt;Declaring a variable doesn’t allocate memory for its storage or even register it in the current &lt;a href=&quot;https://realpython.com/python-namespace/&quot;&gt;namespace&lt;/a&gt;. Still, it can be useful for communicating the expected type to other people reading your code or a &lt;a href=&quot;/ref/glossary/static-type-checker/&quot; class=&quot;ref-link&quot;&gt;static type checker&lt;/a&gt;. Another common use case is instructing the &lt;a href=&quot;/ref/glossary/interpreter/&quot; class=&quot;ref-link&quot;&gt;Python interpreter&lt;/a&gt; to generate &lt;a href=&quot;https://en.wikipedia.org/wiki/Boilerplate_code&quot;&gt;boilerplate code&lt;/a&gt; on your behalf, such as when working with &lt;a href=&quot;/ref/glossary/data-class/&quot; class=&quot;ref-link&quot;&gt;data classes&lt;/a&gt;. You’ll explore these scenarios in the next section.&lt;/p&gt;
&lt;p&gt;To give you a better idea of what Python annotations might look like in practice, below are concrete examples of syntactically correct variable annotations:&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;span class=&quot;mr-2&quot; aria-label=&quot;Filename&quot;&gt;&lt;code style=&quot;color: inherit; background: inherit;&quot;&gt;Python 3.6+&lt;/code&gt;&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.770597e4ea96.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;temperature&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;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pressure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;unit&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;kPa&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;min&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;220&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;max&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;270&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.770597e4ea96.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.770597e4ea96.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 annotate the variable &lt;code&gt;temperature&lt;/code&gt; with &lt;a href=&quot;/ref/builtin-types/float/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;float&lt;/code&gt;&lt;/a&gt; to indicate its expected type. For the variable &lt;code&gt;pressure&lt;/code&gt;, you use a &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;Python dictionary&lt;/a&gt; to specify the air pressure unit along with its minimum and maximum values. This kind of metadata could be used to validate the actual value at runtime, &lt;a href=&quot;https://realpython.com/documenting-python-code/&quot;&gt;generate documentation&lt;/a&gt; based on the source code, or even automatically &lt;a href=&quot;https://realpython.com/command-line-interfaces-python-argparse/&quot;&gt;build a command-line interface&lt;/a&gt; for a &lt;a href=&quot;https://realpython.com/python-script-structure/&quot;&gt;Python script&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-annotations/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-annotations/ »&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: Working With Python&#x27;s .__dict__ Attribute</title>
      <id>https://realpython.com/quizzes/working-dict-attributes/</id>
      <link href="https://realpython.com/quizzes/working-dict-attributes/"/>
      <updated>2025-08-27T12:00:00+00:00</updated>
      <summary>Practice how Python&#x27;s .__dict__ attribute works for classes, instances, and functions, and when mappingproxy and __slots__ come into play.</summary>
      <content type="html">
        &lt;p&gt;This quiz helps you sharpen your understanding of Python&amp;rsquo;s &lt;code&gt;.__dict__&lt;/code&gt; attribute. You&amp;rsquo;ll revisit how attributes are stored, who actually has a &lt;code&gt;.__dict__&lt;/code&gt;, what mappingproxy means, and why &lt;code&gt;__slots__&lt;/code&gt; matters.&lt;/p&gt;
&lt;p&gt;Get ready to test your knowledge after watching &lt;a href=&quot;https://realpython.com/courses/working-dict-attributes/&quot;&gt;Working With Python&amp;rsquo;s &lt;code&gt;.__dict__&lt;/code&gt; Attribute&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>Quiz: Python Annotations</title>
      <id>https://realpython.com/quizzes/python-annotations/</id>
      <link href="https://realpython.com/quizzes/python-annotations/"/>
      <updated>2025-08-27T12:00:00+00:00</updated>
      <summary>Test your knowledge of annotations and type hints, including how different Python versions evaluate them at runtime.</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-annotations/&quot;&gt;lazy annotations&lt;/a&gt; introduced in Python 3.14.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how they improve performance, address forward reference issues, and support both static type checking and runtime processing.&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>Profiling Performance in Python</title>
      <id>https://realpython.com/courses/profiling-performance/</id>
      <link href="https://realpython.com/courses/profiling-performance/"/>
      <updated>2025-08-26T14:00:00+00:00</updated>
      <summary>Learn to profile Python programs with built-in and popular third-party tools, and turn performance insights into faster code.</summary>
      <content type="html">
        &lt;p&gt;Do you want to optimize the performance of your Python program to make it run faster or consume less memory? Before diving into any performance tuning, you should strongly consider using a technique called &lt;strong&gt;software profiling&lt;/strong&gt;. It can help you decide whether optimizing the code is necessary and, if so, which parts of the code you should focus on.&lt;/p&gt;
&lt;p&gt;Sometimes, the return on investment in performance optimizations just isn&amp;rsquo;t worth the effort. If you only run your code once or twice, or if it takes longer to improve the code than execute it, then what&amp;rsquo;s the point?&lt;/p&gt;
&lt;p&gt;When it comes to improving the quality of your code, you&amp;rsquo;ll probably optimize for performance as a final step, if you do it at all. Often, your code will become speedier and more memory efficient thanks to other changes that you make. When in doubt, go through this short checklist to figure out whether to work on performance:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/tutorials/testing/&quot;&gt;Testing&lt;/a&gt;: Have you tested your code to prove that it works as expected and without errors?&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-refactoring/&quot;&gt;Refactoring&lt;/a&gt;: Does your code need some cleanup to become more maintainable and &lt;a href=&quot;https://realpython.com/learning-paths/writing-pythonic-code/&quot;&gt;Pythonic&lt;/a&gt;?&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-timer/#finding-bottlenecks-in-your-code-with-profilers&quot;&gt;Profiling&lt;/a&gt;: Have you identified the most inefficient parts of your code?&lt;/li&gt;
&lt;/ol&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 Write Docstrings in Python</title>
      <id>https://realpython.com/how-to-write-docstrings-in-python/</id>
      <link href="https://realpython.com/how-to-write-docstrings-in-python/"/>
      <updated>2025-08-25T14:00:00+00:00</updated>
      <summary>Learn to write effective Python docstrings that clearly and professionally document your code using best practices and built-in conventions.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Writing clear, consistent docstrings in Python helps others understand your code’s purpose, parameters, and outputs. In this guide on how to write docstrings in Python, you’ll learn about best practices, standard formats, and common pitfalls to avoid, ensuring your documentation is accessible to users and tools alike.&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;Docstrings are strings used to &lt;strong&gt;document your Python code&lt;/strong&gt; and can be accessed at runtime.&lt;/li&gt;
&lt;li&gt;Python &lt;strong&gt;comments and docstrings&lt;/strong&gt; have important differences.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One-line&lt;/strong&gt; and &lt;strong&gt;multiline docstrings&lt;/strong&gt; are classifications of docstrings.&lt;/li&gt;
&lt;li&gt;Common docstring formats include &lt;strong&gt;reStructuredText&lt;/strong&gt;, &lt;strong&gt;Google-style&lt;/strong&gt;, &lt;strong&gt;NumPy-style&lt;/strong&gt;, and &lt;strong&gt;doctest-style&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Antipatterns&lt;/strong&gt; such as inconsistent formatting &lt;strong&gt;should be avoided&lt;/strong&gt; when writing docstrings.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Explore the following sections to see concrete examples and detailed explanations for crafting effective docstrings in your Python projects.&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/how-to-write-docstrings-in-python-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-how-to-write-docstrings-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 shows you how to write docstrings 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.770597e4ea96.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 Write Docstrings 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/how-to-write-docstrings-in-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: #ffc973;&quot; alt=&quot;How to Write Docstrings in Python&quot; src=&quot;https://files.realpython.com/media/How-to-Write-Docstrings-in-Python.e9dd7ff14ce7.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-Write-Docstrings-in-Python.e9dd7ff14ce7.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Write-Docstrings-in-Python.e9dd7ff14ce7.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Write-Docstrings-in-Python.e9dd7ff14ce7.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Write-Docstrings-in-Python.e9dd7ff14ce7.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.770597e4ea96.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/how-to-write-docstrings-in-python/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;How to Write Docstrings in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your knowledge of Python docstrings, including syntax, conventions, formats, and how to access and generate documentation.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-started-with-docstrings-in-python&quot;&gt;Getting Started With Docstrings in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-started-with-docstrings-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python &lt;a href=&quot;/ref/glossary/docstring/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;docstrings&lt;/strong&gt;&lt;/a&gt; are string literals that show information regarding Python functions, classes, methods, and modules, allowing them to be properly documented. They are placed immediately after the definition line in triple double quotes (&lt;code&gt;&quot;&quot;&quot;&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Their use and convention are described in &lt;a href=&quot;https://peps.python.org/pep-0257/&quot;&gt;PEP 257&lt;/a&gt;, which is a &lt;a href=&quot;/ref/glossary/pep/&quot; class=&quot;ref-link&quot;&gt;Python Enhancement Proposal (PEP)&lt;/a&gt; that outlines conventions for writing docstrings. Docstrings don’t follow a strict formal style. 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;docstring_format.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;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;determine_magic_level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;magic_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Multiply a wizard&#x27;s favorite number by 3 to reveal their magic level.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&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;3&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.770597e4ea96.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.770597e4ea96.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;Docstrings are a built-in means of documentation. While this may remind you of &lt;a href=&quot;https://realpython.com/python-comments-guide/&quot;&gt;comments in Python&lt;/a&gt;, docstrings serve a distinct purpose. If you’re curious and would like to see a quick breakdown of the differences now, open the collapsible section below.&lt;/p&gt;
&lt;div class=&quot;card mb-3&quot; id=&quot;collapse_card810779&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;#collapse810779&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapse810779&quot; markdown=&quot;1&quot;&gt;&lt;span class=&quot;float-left&quot; markdown=&quot;1&quot;&gt;Differences Between Python Comments and Docstrings&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_card810779&quot; id=&quot;collapse810779&quot;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;p&gt;Python comments and docstrings seem a lot alike, but they’re actually quite different in a number of ways because they serve different purposes:&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;Comments&lt;/th&gt;
&lt;th&gt;Docstrings&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Begin with &lt;code&gt;#&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Are enclosed in triple quotes (&lt;code&gt;&quot;&quot;&quot;&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Consist of notes and reminders written by developers for other developers&lt;/td&gt;
&lt;td&gt;Provide documentation for users and tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Are ignored by the Python interpreter&lt;/td&gt;
&lt;td&gt;Are stored in &lt;code&gt;.__doc__&lt;/code&gt; and accessible at runtime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can be placed anywhere in code&lt;/td&gt;
&lt;td&gt;Are placed at the start of modules, classes, and functions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;To summarize, comments explain parts of an implementation that may not be obvious or that record important notes for other developers. Docstrings describe modules, classes, and functions so users and tools can access that information at runtime.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;So, while comments and docstrings may look similar at first glance, their purpose and behavior in Python are different. Next, you’ll look at one-line and multiline docstrings.&lt;/p&gt;
&lt;h3 id=&quot;one-line-vs-multiline-docstrings&quot;&gt;One-Line vs Multiline Docstrings&lt;a class=&quot;headerlink&quot; href=&quot;#one-line-vs-multiline-docstrings&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Docstrings are generally classified as either one-line or multiline. As the names suggest, one-line docstrings take up only a single line, while multiline docstrings span more than one line. While this may appear to be a slight difference, how you use and format them in your code matters.&lt;/p&gt;
&lt;p&gt;An important formatting rule from PEP 257 is that one-line docstrings should be concise, while multiline docstrings should have their closing quotes on a new line. You may resort to a one-line docstring for relatively straightforward programs like the one below:&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;one_line_docstring.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;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;random&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;picking_hat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&quot;&quot;&quot;Return a random house name.&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;houses&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;s2&quot;&gt;&quot;Gryffindor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hufflepuff&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Ravenclaw&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Slytherin&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;houses&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.770597e4ea96.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.770597e4ea96.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 see a program that returns a random house as depicted in the classic Harry Potter stories. This is a good example for the use of one-line docstrings.&lt;/p&gt;
&lt;p&gt;You use multiline docstrings when you have to provide a more thorough explanation of your code, which is helpful for other developers. Generally, a docstring should contain parameters, return value details, and a summary of the code. &lt;/p&gt;
&lt;p&gt;You’re free to format docstrings as you like. That being said, you’ll learn later that there are common docstring formats that you may follow. Here’s an example of a multiline docstring:&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;multiline_docstring.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;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get_harry_potter_book&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;publication_year&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Retrieve a Harry Potter book by its publication year and name.&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    Parameters:&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    publication_year (int): The year the book was published.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    title (str): The title of the book.&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    Returns:&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    str: A sentence describing the book and its publication year.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;The book &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;!r}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; was published in the year &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;publication_year&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&quot;&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.770597e4ea96.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.770597e4ea96.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;As you can see, the closing quotes for this multiline docstring appear on a separate line. Now that you understand the difference between one-line and multiline docstrings, you’ll learn how to access docstrings in your code.&lt;/p&gt;
&lt;h3 id=&quot;ways-to-access-docstrings-in-python&quot;&gt;Ways to Access Docstrings in Python&lt;a class=&quot;headerlink&quot; href=&quot;#ways-to-access-docstrings-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Unlike code &lt;a href=&quot;/ref/glossary/comment/&quot; class=&quot;ref-link&quot;&gt;comments&lt;/a&gt;, docstrings aren’t ignored by the interpreter. They become a part of the program and serve as associated documentation for anyone who wants to understand your program and what it does. That’s why knowing how to access docstrings is so useful. Python provides two built-in ways to access docstrings: the &lt;strong&gt;&lt;code&gt;.__doc__&lt;/code&gt; attribute&lt;/strong&gt; and the &lt;strong&gt;&lt;code&gt;help()&lt;/code&gt; function&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;the-__doc__-attribute&quot;&gt;The &lt;code&gt;.__doc__&lt;/code&gt; Attribute&lt;a class=&quot;headerlink&quot; href=&quot;#the-__doc__-attribute&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/how-to-write-docstrings-in-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/how-to-write-docstrings-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>Quiz: How to Write Docstrings in Python</title>
      <id>https://realpython.com/quizzes/how-to-write-docstrings-in-python/</id>
      <link href="https://realpython.com/quizzes/how-to-write-docstrings-in-python/"/>
      <updated>2025-08-25T12:00:00+00:00</updated>
      <summary>Test your knowledge of Python docstrings, including syntax, conventions, formats, and how to access and generate documentation.</summary>
      <content type="html">
        &lt;p&gt;Want to get comfortable writing and using Python docstrings? This quiz helps you revisit best practices, standard conventions, and common tools.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll review the basics of docstring syntax, how to read them at runtime, and different formatting styles. For more details, check out the tutorial &lt;a href=&quot;https://realpython.com/how-to-write-docstrings-in-python/&quot;&gt;How to Write Docstrings 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>Quiz: Python Skill Test</title>
      <id>https://realpython.com/quizzes/python-skill-test/</id>
      <link href="https://realpython.com/quizzes/python-skill-test/"/>
      <updated>2025-08-24T12:00:00+00:00</updated>
      <summary>Test your Python knowledge in a skill quiz with basic to advanced questions. Are you a Novice, Intermediate, Proficient, or Expert?</summary>
      <content type="html">
        &lt;p&gt;🐍 &lt;strong&gt;How Strong Are Your Python Skills?&lt;/strong&gt; 🚀&lt;/p&gt;
&lt;p&gt;This quick quiz gives you a &lt;strong&gt;snapshot of where you stand&lt;/strong&gt;, whether you&amp;rsquo;re just starting out with Python or have years of coding under your belt.&lt;/p&gt;
&lt;p&gt;Test your Python skill by answering questions ranging from fundamentals to more advanced challenges. Each question is designed to test your understanding and maybe even teach you something new.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Read the &lt;em&gt;Explanation&lt;/em&gt; for each answer and follow the included links to study up.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;See where you currently place and get tips and resources to progress quickly:&lt;/p&gt;
&lt;figure class=&quot;&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/novice-to-expert-graph.49ff983f368e.png&quot; width=&quot;3840&quot; height=&quot;427&quot; srcset=&quot;/cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/novice-to-expert-graph.49ff983f368e.png 960w, /cdn-cgi/image/width=1280,format=auto/https://files.realpython.com/media/novice-to-expert-graph.49ff983f368e.png 1280w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/novice-to-expert-graph.49ff983f368e.png 1920w, /cdn-cgi/image/width=3840,format=auto/https://files.realpython.com/media/novice-to-expert-graph.49ff983f368e.png 3840w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;A graph showing bounded boxes from Novice to Intermediate to Proficient to Expert&quot; data-asset=&quot;6488&quot;/&gt;&lt;/figure&gt;

&lt;p&gt;Click below to start the quiz and find out!&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 #262: Travis Oliphant: SciPy, NumPy, and Fostering Scientific Python</title>
      <id>https://realpython.com/podcasts/rpp/262/</id>
      <link href="https://realpython.com/podcasts/rpp/262/"/>
      <updated>2025-08-22T12:00:00+00:00</updated>
      <summary>What went into developing the open-source Python tools data scientists use every day? This week on the show, we talk with Travis Oliphant about his work on SciPy, NumPy, Numba, and many other contributions to the Python scientific community.</summary>
      <content type="html">
        &lt;p&gt;What went into developing the open-source Python tools data scientists use every day? This week on the show, we talk with Travis Oliphant about his work on SciPy, NumPy, Numba, and many other contributions to the Python scientific 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>
  
    <entry>
      <title>Working With JSON Data in Python</title>
      <id>https://realpython.com/python-json/</id>
      <link href="https://realpython.com/python-json/"/>
      <updated>2025-08-20T14:00:00+00:00</updated>
      <summary>Learn how to work with JSON data in Python using the json module. Convert, read, write, and validate JSON files and handle JSON data for APIs and storage.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;json&lt;/code&gt; module provides you with the tools you need to effectively handle JSON data. You can convert Python data types to a JSON-formatted string with &lt;code&gt;json.dumps()&lt;/code&gt; or write them to files using &lt;code&gt;json.dump()&lt;/code&gt;. Similarly, you can read JSON data from files with &lt;code&gt;json.load()&lt;/code&gt; and parse JSON strings with &lt;code&gt;json.loads()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;JSON, or JavaScript Object Notation, is a widely-used text-based format for data interchange. Its syntax resembles Python dictionaries but with some differences, such as using only double quotes for strings and lowercase for Boolean values. With built-in tools for validating syntax and manipulating JSON files, Python makes it straightforward to work with JSON data.&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;JSON in Python is handled using the &lt;strong&gt;standard-library &lt;code&gt;json&lt;/code&gt; module&lt;/strong&gt;, which allows for &lt;strong&gt;data interchange&lt;/strong&gt; between JSON and Python data types.&lt;/li&gt;
&lt;li&gt;JSON is a good data format to use with Python as it’s &lt;strong&gt;human-readable&lt;/strong&gt; and straightforward to &lt;strong&gt;serialize and deserialize&lt;/strong&gt;, which makes it ideal for use in &lt;strong&gt;APIs and data storage&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You write JSON with Python using &lt;strong&gt;&lt;code&gt;json.dump()&lt;/code&gt;&lt;/strong&gt; to serialize data to a file.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;minify and prettify JSON&lt;/strong&gt; using Python’s &lt;code&gt;json.tool&lt;/code&gt; module.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since its introduction, &lt;a href=&quot;https://en.wikipedia.org/wiki/JSON&quot;&gt;JSON&lt;/a&gt; has rapidly emerged as the predominant standard for the exchange of information. Whether you want to transfer data with an &lt;a href=&quot;https://realpython.com/api-integration-in-python/&quot;&gt;API&lt;/a&gt; or store information in a &lt;a href=&quot;https://realpython.com/introduction-to-mongodb-and-python/&quot;&gt;document database&lt;/a&gt;, it’s likely you’ll encounter JSON. Fortunately, Python provides robust tools to facilitate this process and help you manage JSON data efficiently.&lt;/p&gt;
&lt;p&gt;While JSON is the most common format for data distribution, it’s not the only option for such tasks. Both &lt;a href=&quot;https://realpython.com/python-xml-parser/&quot;&gt;XML&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-yaml/&quot;&gt;YAML&lt;/a&gt; serve similar purposes. If you’re interested in how the formats differ, then you can check out the tutorial on how to &lt;a href=&quot;https://realpython.com/python-serialize-data/&quot;&gt;serialize your data with Python&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;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-json/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-json&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 work with JSON data 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.770597e4ea96.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 “Working With JSON Data 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-json/&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;Working With JSON Data in Python&quot; src=&quot;https://files.realpython.com/media/Working-With-JSON-Data-in-Python_Watermarked.66a8fdcb8859.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Working-With-JSON-Data-in-Python_Watermarked.66a8fdcb8859.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Working-With-JSON-Data-in-Python_Watermarked.66a8fdcb8859.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Working-With-JSON-Data-in-Python_Watermarked.66a8fdcb8859.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Working-With-JSON-Data-in-Python_Watermarked.66a8fdcb8859.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.770597e4ea96.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-json/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Working With JSON Data in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of working with JSON in Python. By working through this quiz, you&#x27;ll revisit key concepts related to JSON data manipulation and handling in Python.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;introducing-json&quot;&gt;Introducing JSON&lt;a class=&quot;headerlink&quot; href=&quot;#introducing-json&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The acronym &lt;strong&gt;JSON&lt;/strong&gt; stands for &lt;a href=&quot;https://www.json.org/&quot;&gt;JavaScript Object Notation&lt;/a&gt;. As the name suggests, JSON originated from &lt;a href=&quot;https://realpython.com/python-vs-javascript/&quot;&gt;JavaScript&lt;/a&gt;. However, JSON has transcended its origins to become language-agnostic and is now recognized as the &lt;a href=&quot;https://tools.ietf.org/html/rfc8259&quot;&gt;standard&lt;/a&gt; for &lt;strong&gt;data interchange&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The popularity of JSON can be attributed to native support by the JavaScript language, resulting in excellent parsing performance in web browsers. On top of that, JSON’s straightforward syntax allows both humans and computers to read and write JSON data effortlessly.&lt;/p&gt;
&lt;p&gt;To get a first impression of JSON, have a look at this example code:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;json&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--purple&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;JSON&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;hello_world.json&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;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;greeting&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, world!&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.770597e4ea96.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.770597e4ea96.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’ll learn more about the JSON syntax later in this tutorial. For now, recognize that the JSON format is &lt;strong&gt;text-based&lt;/strong&gt;. In other words, you can create JSON files using the code editor of your choice. Once you set the file extension to &lt;code&gt;.json&lt;/code&gt;, most code editors display your JSON data with syntax highlighting out of the box:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/json-syntax-highlighting.bf172e2b07bd.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/json-syntax-highlighting.bf172e2b07bd.png&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/json-syntax-highlighting.bf172e2b07bd.png 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/json-syntax-highlighting.bf172e2b07bd.png 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/json-syntax-highlighting.bf172e2b07bd.png 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/json-syntax-highlighting.bf172e2b07bd.png 1920w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Editor screenshot with code highlighting for a JSON file&quot; data-asset=&quot;5839&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;The screenshot above shows how &lt;a href=&quot;https://realpython.com/python-development-visual-studio-code/&quot;&gt;VS Code&lt;/a&gt; displays JSON data using the &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=BeardedBear.beardedtheme&quot;&gt;Bearded color theme&lt;/a&gt;. You’ll have a closer look at the syntax of the JSON format next!&lt;/p&gt;
&lt;h3 id=&quot;examining-json-syntax&quot;&gt;Examining JSON Syntax&lt;a class=&quot;headerlink&quot; href=&quot;#examining-json-syntax&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In the previous section, you got a first impression of how JSON data looks. And as a Python developer, the JSON structure probably reminds you of &lt;a href=&quot;https://realpython.com/python-data-structures/&quot;&gt;common Python data structures&lt;/a&gt;, like a dictionary that contains a string as a key and a value. If you understand the syntax of a &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt; in Python, you already know the general syntax of a &lt;strong&gt;JSON object&lt;/strong&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; Later in this tutorial, you’ll learn that you’re free to use lists and other data types at the top level of a JSON document.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The similarity between Python dictionaries and JSON objects is no surprise. One idea behind establishing JSON as the go-to data interchange format was to make working with JSON as convenient as possible, independently of which programming language you use:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;[A collection of key-value pairs and arrays] are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages is also based on these structures. (&lt;a href=&quot;https://www.json.org/json-en.html&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To explore the JSON syntax further, create a new file named &lt;code&gt;hello_frieda.json&lt;/code&gt; and add a more complex JSON structure as the content of the file:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;json&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--purple&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;JSON&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;hello_frieda.json&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;linenos&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Frieda&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 3&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;isDog&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;hobbies&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;eating&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;sleeping&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;barking&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;age&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 6&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;address&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 7&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;work&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 8&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;home&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Berlin&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Germany&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 9&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;friends&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Philipp&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;hobbies&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;eating&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;sleeping&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;reading&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Mitch&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;      &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;hobbies&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;running&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;snacking&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;20&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.770597e4ea96.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.770597e4ea96.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 the code above, you see data about a dog named Frieda, which is formatted as JSON. The top-level value is a JSON object. Just like Python dictionaries, you wrap JSON objects inside curly braces (&lt;code&gt;{}&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;In line 1, you start the JSON object with an opening curly brace (&lt;code&gt;{&lt;/code&gt;), and then you close the object at the end of line 20 with a closing curly brace (&lt;code&gt;}&lt;/code&gt;).&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-json/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-json/ »&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>Deep vs Shallow Copies in Python</title>
      <id>https://realpython.com/courses/deep-vs-shallow-copies/</id>
      <link href="https://realpython.com/courses/deep-vs-shallow-copies/"/>
      <updated>2025-08-19T14:00:00+00:00</updated>
      <summary>Understand the difference between shallow and deep copies in Python. Learn how to duplicate objects safely using the copy module and other techniques.</summary>
      <content type="html">
        &lt;p&gt;When working with Python objects, you&amp;rsquo;ll often need to make copies rather than modify the originals. In this video course, you&amp;rsquo;ll explore various ways to copy objects in Python, including using the built-in &lt;code&gt;copy&lt;/code&gt; module. You&amp;rsquo;ll also learn the key differences between shallow and deep copies, with practical examples so you can safely duplicate objects in your own code.&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;Shallow copying&lt;/strong&gt; creates a new object but references the same nested objects, leading to shared changes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deep copying&lt;/strong&gt; recursively duplicates all objects, ensuring full independence from the original.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Python&amp;rsquo;s &lt;code&gt;copy&lt;/code&gt; module&lt;/strong&gt; provides the &lt;code&gt;copy()&lt;/code&gt; function for shallow copies and &lt;code&gt;deepcopy()&lt;/code&gt; for deep copies.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom classes&lt;/strong&gt; can implement &lt;code&gt;.__copy__()&lt;/code&gt; and &lt;code&gt;.__deepcopy__()&lt;/code&gt; for specific copying behavior.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Assignment in Python&lt;/strong&gt; binds variable names to objects without copying, unlike some lower-level languages.&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>Single and Double Underscores in Python Names</title>
      <id>https://realpython.com/python-double-underscore/</id>
      <link href="https://realpython.com/python-double-underscore/"/>
      <updated>2025-08-18T14:00:00+00:00</updated>
      <summary>Learn Python naming conventions with single and double underscores to design APIs, create safe classes, and prevent name clashes.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python has a few naming conventions that are based on using either a single or double underscore character (&lt;code&gt;_&lt;/code&gt;). These conventions allow you to differentiate between public and non-public names in APIs, write subclasses safely, prevent name collisions, and more.&lt;/p&gt;
&lt;p&gt;Following these conventions makes your code look more Pythonic and consistent to other developers. This skill is especially helpful when you’re working on collaborative projects.&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;Underscores&lt;/strong&gt; in Python names &lt;strong&gt;indicate intent&lt;/strong&gt;: a single leading underscore signals a &lt;strong&gt;non-public name&lt;/strong&gt;, a single trailing underscore helps avoid &lt;strong&gt;naming conflicts&lt;/strong&gt;, and a double leading underscore triggers &lt;strong&gt;name mangling&lt;/strong&gt; for class attributes and methods.&lt;/li&gt;
&lt;li&gt;Python doesn’t enforce &lt;strong&gt;public&lt;/strong&gt; or &lt;strong&gt;private&lt;/strong&gt; names with access restrictions. It relies on naming conventions, where &lt;strong&gt;public names&lt;/strong&gt; have no underscores and &lt;strong&gt;non-public names&lt;/strong&gt; start with a single underscore.&lt;/li&gt;
&lt;li&gt;Python’s &lt;strong&gt;name mangling&lt;/strong&gt; automatically renames attributes or methods with double leading underscores by &lt;strong&gt;prefixing them with the class name&lt;/strong&gt;, helping you avoid accidental overrides in subclasses.&lt;/li&gt;
&lt;li&gt;Double leading and trailing underscores—known as &lt;strong&gt;dunders&lt;/strong&gt;—denote &lt;strong&gt;special methods&lt;/strong&gt; or &lt;strong&gt;attributes&lt;/strong&gt;, such as &lt;code&gt;.__init__()&lt;/code&gt;, &lt;code&gt;.__len__()&lt;/code&gt;, and &lt;code&gt;__name__&lt;/code&gt;, which Python uses to support internal behaviors.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll explore practical examples of these naming conventions, learn when and why to use each one, and understand their effects on code readability, API design, and inheritance.&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-double-underscore-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-double-underscore-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 single and double underscores in Python names.&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.770597e4ea96.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 “Single and Double Underscores in Python Names” 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-double-underscore/&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;Single and Double Underscores in Python Names&quot; src=&quot;https://files.realpython.com/media/Single-and-a-Double-Leading-Underscore-in-Python-Names_Watermarked.e3bfbf1b525c.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Single-and-a-Double-Leading-Underscore-in-Python-Names_Watermarked.e3bfbf1b525c.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Single-and-a-Double-Leading-Underscore-in-Python-Names_Watermarked.e3bfbf1b525c.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Single-and-a-Double-Leading-Underscore-in-Python-Names_Watermarked.e3bfbf1b525c.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Single-and-a-Double-Leading-Underscore-in-Python-Names_Watermarked.e3bfbf1b525c.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.770597e4ea96.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-double-underscore/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Single and Double Underscores in Python Names&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of the use of single and double underscores in Python names. This knowledge will help you differentiate between public and non-public names, avoid name clashes, and write code that looks Pythonic and consistent.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;public-interfaces-and-naming-conventions-in-python&quot;&gt;Public Interfaces and Naming Conventions in Python&lt;a class=&quot;headerlink&quot; href=&quot;#public-interfaces-and-naming-conventions-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;As a Python programmer, you’ll frequently work with &lt;strong&gt;public interfaces&lt;/strong&gt;, known as &lt;a href=&quot;/ref/glossary/api/&quot; class=&quot;ref-link&quot;&gt;application programming interfaces (APIs)&lt;/a&gt;. An API is a type of programming interface that offers a service to other parts of a program or other programs.&lt;/p&gt;
&lt;p&gt;For example, the Python &lt;a href=&quot;/ref/glossary/standard-library/&quot; class=&quot;ref-link&quot;&gt;standard library&lt;/a&gt; has many &lt;a href=&quot;https://realpython.com/python-modules-packages/&quot;&gt;modules and packages&lt;/a&gt; that provide certain services. To use these &lt;a href=&quot;/ref/glossary/module/&quot; class=&quot;ref-link&quot;&gt;modules&lt;/a&gt; and &lt;a href=&quot;/ref/glossary/package/&quot; class=&quot;ref-link&quot;&gt;packages&lt;/a&gt;, you need to access their &lt;a href=&quot;/ref/glossary/public-name/&quot; class=&quot;ref-link&quot;&gt;&lt;em&gt;public&lt;/em&gt;&lt;/a&gt; components, such as &lt;a href=&quot;/ref/glossary/class/&quot; class=&quot;ref-link&quot;&gt;classes&lt;/a&gt;, &lt;a href=&quot;/ref/glossary/function/&quot; class=&quot;ref-link&quot;&gt;functions&lt;/a&gt;, &lt;a href=&quot;/ref/glossary/variable/&quot; class=&quot;ref-link&quot;&gt;variables&lt;/a&gt;, constants, and modules. All these &lt;a href=&quot;/ref/glossary/object/&quot; class=&quot;ref-link&quot;&gt;objects&lt;/a&gt; are part of the module or package’s public interface. They’re available for you to use directly in your code.&lt;/p&gt;
&lt;p&gt;However, many of these packages and modules define objects that aren’t intended for direct access. These objects are meant for internal use within the specific package or module and aren’t part of its public interface.&lt;/p&gt;
&lt;p&gt;In the context of &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt;, languages like &lt;a href=&quot;https://realpython.com/python-vs-cpp/&quot;&gt;C++&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/java-vs-python/&quot;&gt;Java&lt;/a&gt; have the notion of &lt;strong&gt;public&lt;/strong&gt; and &lt;strong&gt;private&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/python-classes/#providing-behavior-with-methods&quot;&gt;methods&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-classes/#attaching-data-to-classes-and-instances&quot;&gt;attributes&lt;/a&gt;—jointly called &lt;strong&gt;members&lt;/strong&gt;. In these languages, you can use these types of class members as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Public&lt;/strong&gt;: You can use them in your own code or client code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Private&lt;/strong&gt;: You can use them only from inside the defining class and its subclasses.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These languages have specific keywords and syntax to define public and private members in their classes. Once you declare a member as private, you can’t use it outside the class because the language restricts access. So, private members aren’t part of the class’s public interface, and there’s no way to access them.&lt;/p&gt;
&lt;p&gt;In contrast, Python doesn’t have the notion of public and private members. It has neither dedicated &lt;a href=&quot;https://realpython.com/python-keywords/&quot;&gt;keywords&lt;/a&gt; nor syntax for defining them. Therefore, you can always access the members of a Python class.&lt;/p&gt;
&lt;p&gt;If Python doesn’t have a specific syntax to define when an object is part of a public interface, then how do you tell your users that they &lt;em&gt;can&lt;/em&gt; or &lt;em&gt;can’t&lt;/em&gt; use a given class, method, function, variable, constant, or even module in their code?&lt;/p&gt;
&lt;p&gt;To approach this question, the Python community has a well-established &lt;strong&gt;naming convention&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If a name starts with a letter in uppercase or lowercase, then you should consider that name public and, therefore, part of the code’s API. In contrast, if a name starts with an underscore character (&lt;code&gt;_&lt;/code&gt;), then you should consider that name non-public, meaning it’s not a part of the public API.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You should observe these naming conventions to explicitly indicate whether other developers should directly use your variables, constants, functions, methods, and modules in external code.&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; This naming convention doesn’t restrict access to objects. It only signals to other developers how the code is intended to be used. Because of this, Python programmers avoid the terms public and private. Instead, they distinguish between &lt;a href=&quot;/ref/glossary/public-name/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;public&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;/ref/glossary/non-public-name/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;non-public (internal)&lt;/strong&gt;&lt;/a&gt; names.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The Python community uses the underscore character (&lt;code&gt;_&lt;/code&gt;) as part of other naming conventions. Here’s a summary of what &lt;a href=&quot;https://peps.python.org/pep-0008/&quot;&gt;PEP 8&lt;/a&gt; says about using this character in names:&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;Convention&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;Single leading underscore&lt;/td&gt;
&lt;td&gt;&lt;code&gt;_variable&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Indicates that the name is meant for internal use only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Single trailing underscore&lt;/td&gt;
&lt;td&gt;&lt;code&gt;class_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Avoids naming conflicts with Python keywords and built-in names&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Double leading underscore&lt;/td&gt;
&lt;td&gt;&lt;code&gt;__attribute&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Triggers name mangling in the context of Python classes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Double leading and trailing underscore&lt;/td&gt;
&lt;td&gt;&lt;code&gt;__name__&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Indicates special attributes and methods that Python provides&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Single underscore&lt;/td&gt;
&lt;td&gt;&lt;code&gt;_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Indicates a temporary or throwaway variable&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Note that only two of these &lt;a href=&quot;https://realpython.com/python-pep8/#naming-conventions&quot;&gt;naming conventions&lt;/a&gt; enforce specific Python behaviors. Using double leading underscores triggers &lt;strong&gt;name mangling&lt;/strong&gt; in Python classes. You’ll learn more about this behavior in the section on &lt;a href=&quot;#double-leading-underscore-in-classes-pythons-name-mangling&quot;&gt;name mangling&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Additionally, those names with double leading and trailing underscores that are listed in the Python &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html&quot;&gt;data model&lt;/a&gt; trigger internal behaviors in specific contexts. You’ll also learn more about this topic in the section on &lt;a href=&quot;#dunder-names-in-python&quot;&gt;dunder names in Python&lt;/a&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; Python also treats a single &lt;a href=&quot;/ref/keywords/underscore/&quot; class=&quot;ref-link&quot;&gt;underscore (&lt;code&gt;_&lt;/code&gt;)&lt;/a&gt; as a &lt;a href=&quot;/ref/glossary/soft-keyword/&quot; class=&quot;ref-link&quot;&gt;soft keyword&lt;/a&gt; within &lt;code&gt;match&lt;/code&gt; … &lt;code&gt;case&lt;/code&gt; statements. You’ll learn more about this &lt;a href=&quot;#other-uses-of-underscores-in-python&quot;&gt;later&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-double-underscore/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-double-underscore/ »&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 #261: Selecting Inheritance or Composition in Python</title>
      <id>https://realpython.com/podcasts/rpp/261/</id>
      <link href="https://realpython.com/podcasts/rpp/261/"/>
      <updated>2025-08-15T12:00:00+00:00</updated>
      <summary>When considering an object-oriented programming problem, should you prefer inheritance or composition? Why wouldn&#x27;t it just be simpler to use functions? 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;When considering an object-oriented programming problem, should you prefer inheritance or composition? Why wouldn&#x27;t it just be simpler to use functions? 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>Python&#x27;s with Statement: Manage External Resources Safely</title>
      <id>https://realpython.com/python-with-statement/</id>
      <link href="https://realpython.com/python-with-statement/"/>
      <updated>2025-08-13T14:00:00+00:00</updated>
      <summary>Understand Python&#x27;s with statement and context managers to streamline the setup and teardown phases in resource management. Start writing safer code today!</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;with&lt;/code&gt; statement allows you to manage external resources safely by using objects that support the context manager protocol. These objects automatically handle the setup and cleanup phases of common operations.&lt;/p&gt;
&lt;p&gt;By using the &lt;code&gt;with&lt;/code&gt; statement alongside appropriate context managers, you can focus on your core logic while the context managers prevent resource leaks like unclosed files, unreleased memory, or dangling network connections.&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;with&lt;/code&gt; statement&lt;/strong&gt; automates the process of setting up and tearing down computational resources using context managers.&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;with&lt;/code&gt; reduces code complexity and &lt;strong&gt;prevents resource leaks&lt;/strong&gt; by ensuring proper resource release, even if exceptions occur.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;context manager&lt;/strong&gt; in Python is an object that implements &lt;strong&gt;&lt;code&gt;.__enter__()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;.__exit__()&lt;/code&gt;&lt;/strong&gt; methods to manage resources safely.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Get ready to learn how Python’s &lt;code&gt;with&lt;/code&gt; statement and context managers streamline the setup and teardown phases of resource management so you can write safer, more reliable 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/python-with-statement-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-with-statement-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 with statement to manage external resources safely.&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.770597e4ea96.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 “Context Managers and Python&#x27;s with Statement” 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-with-statement/&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: #b9abe6;&quot; alt=&quot;Context Managers and Python&#x27;s with Statement&quot; src=&quot;https://files.realpython.com/media/Context-Managers--the-Python-with-Statement_Watermarked.3774ffbe2514.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Context-Managers--the-Python-with-Statement_Watermarked.3774ffbe2514.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Context-Managers--the-Python-with-Statement_Watermarked.3774ffbe2514.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Context-Managers--the-Python-with-Statement_Watermarked.3774ffbe2514.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Context-Managers--the-Python-with-Statement_Watermarked.3774ffbe2514.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.770597e4ea96.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-with-statement/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Context Managers and Python&#x27;s with Statement&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your knowledge of Python&#x27;s with statement and context managers to write cleaner code and manage resources safely and efficiently.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;managing-external-resources-in-python&quot;&gt;Managing External Resources in Python&lt;a class=&quot;headerlink&quot; href=&quot;#managing-external-resources-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Properly managing &lt;strong&gt;external resources&lt;/strong&gt;, such as &lt;a href=&quot;https://realpython.com/working-with-files-in-python/&quot;&gt;files&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Lock_(computer_science)&quot;&gt;locks&lt;/a&gt;, and network connections, is a common requirement in programming. Sometimes, a program uses a given resource and doesn’t release the associated memory when it no longer needs the resource. This kind of issue is called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Memory_leak&quot;&gt;memory leak&lt;/a&gt; because the available memory shrinks every time you create a new instance of a resource without releasing the unneeded ones.&lt;/p&gt;
&lt;p&gt;Managing resources properly is often a tricky task. It requires &lt;strong&gt;setup&lt;/strong&gt; and &lt;strong&gt;teardown&lt;/strong&gt; phases. The latter phase requires you to perform cleanup actions, like &lt;a href=&quot;https://realpython.com/why-close-file-python/&quot;&gt;closing a file&lt;/a&gt;, releasing a lock, or closing a network connection. If you forget to perform these cleanup actions, then your application keeps the resource occupied. This behavior might compromise valuable system resources, such as memory and network bandwidth.&lt;/p&gt;
&lt;p&gt;For example, say that a program that uses databases keeps creating new connections without releasing the old ones or reusing them. In that case, the database &lt;a href=&quot;https://en.wikipedia.org/wiki/Back-end_database&quot;&gt;back end&lt;/a&gt; can stop accepting new connections. This might require an administrator to log in and manually terminate those stale connections to make the database usable again.&lt;/p&gt;
&lt;p&gt;Another common issue occurs when developers work with files. &lt;a href=&quot;https://realpython.com/read-write-files-python/&quot;&gt;Writing text to files&lt;/a&gt; is usually a &lt;a href=&quot;https://realpython.com/python-flush-print-output/#understand-how-python-buffers-output&quot;&gt;buffered&lt;/a&gt; operation. This means that calling &lt;code&gt;.write()&lt;/code&gt; on a file won’t immediately result in writing text to the physical file, but to a temporary buffer. Sometimes, when the buffer isn’t full, developers forget to call &lt;code&gt;.close()&lt;/code&gt; and part of the data can be lost.&lt;/p&gt;
&lt;p&gt;Another possibility is that your application runs into errors or &lt;a href=&quot;https://realpython.com/python-exceptions/&quot;&gt;exceptions&lt;/a&gt; that cause the &lt;a href=&quot;https://realpython.com/python-control-flow/&quot;&gt;control flow&lt;/a&gt; to bypass the code responsible for releasing the resource at hand. Here’s an example where you use the built-in &lt;a href=&quot;https://realpython.com/python-built-in-functions/#opening-files-open&quot;&gt;&lt;code&gt;open()&lt;/code&gt;&lt;/a&gt; function to write some text to a file:&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;n&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;hello.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&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.770597e4ea96.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.770597e4ea96.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;This code doesn’t guarantee the file will be closed if an exception occurs during the call to &lt;code&gt;.write()&lt;/code&gt;. In this situation, the code might never call &lt;code&gt;.close()&lt;/code&gt;, and your program will leak a file descriptor. Failing to release a file descriptor on some operating systems can prevent other programs from accessing the underlying file.&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 closing files, check out the &lt;a href=&quot;https://realpython.com/why-close-file-python/&quot;&gt;Why Is It Important to Close Files in Python?&lt;/a&gt; tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In Python, you can use a couple of general approaches to deal with resource management. You can wrap your code in:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A &lt;a href=&quot;https://realpython.com/python-exceptions/#cleaning-up-after-using-finally&quot;&gt;&lt;code&gt;try&lt;/code&gt; … &lt;code&gt;finally&lt;/code&gt;&lt;/a&gt; construct&lt;/li&gt;
&lt;li&gt;A &lt;a href=&quot;https://docs.python.org/3/reference/compound_stmts.html#the-with-statement&quot;&gt;&lt;code&gt;with&lt;/code&gt;&lt;/a&gt; construct&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first approach is quite generic and allows you to provide setup and teardown code to manage any kind of resource. However, it’s a little bit verbose, and you might forget some cleanup actions if you use this construct in several places.&lt;/p&gt;
&lt;p&gt;The second approach provides a straightforward way to provide and reuse setup and teardown code. In this case, you’ll have the limitation that the &lt;code&gt;with&lt;/code&gt; statement only works with &lt;a href=&quot;/ref/glossary/context-manager/&quot; class=&quot;ref-link&quot;&gt;context managers&lt;/a&gt;. In the next two sections, you’ll learn how to use both approaches in your code.&lt;/p&gt;
&lt;h3 id=&quot;the-try-finally-construct&quot;&gt;The &lt;code&gt;try&lt;/code&gt; … &lt;code&gt;finally&lt;/code&gt; Construct&lt;a class=&quot;headerlink&quot; href=&quot;#the-try-finally-construct&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Working with files is probably the most common example of resource management in programming. In Python, you can use a &lt;strong&gt;&lt;code&gt;try&lt;/code&gt; … &lt;code&gt;finally&lt;/code&gt;&lt;/strong&gt; construct to handle opening and closing files properly:&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;n&quot;&gt;file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;hello.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;w&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&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.770597e4ea96.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.770597e4ea96.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 open the &lt;code&gt;hello.txt&lt;/code&gt; file using &lt;code&gt;open()&lt;/code&gt;. To write some text into the file, you wrap the call to &lt;code&gt;.write()&lt;/code&gt; in a &lt;a href=&quot;/ref/keywords/try/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;try&lt;/code&gt;&lt;/a&gt; statement with a &lt;a href=&quot;/ref/keywords/finally/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;finally&lt;/code&gt;&lt;/a&gt; clause. This clause guarantees that the file is properly closed by calling &lt;code&gt;.close()&lt;/code&gt;, even if an exception occurs during the call to &lt;code&gt;.write()&lt;/code&gt; in the &lt;code&gt;try&lt;/code&gt; clause. Remember that the &lt;code&gt;finally&lt;/code&gt; clause always runs.&lt;/p&gt;
&lt;p&gt;When managing external resources in Python, you can use the construct in the previous example to handle setup and teardown logic. The setup logic might include opening the file and writing content to it, while the teardown logic might consist of closing the file to release the acquired resources.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-with-statement/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-with-statement/ »&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 .__dict__ Attribute</title>
      <id>https://realpython.com/courses/working-dict-attributes/</id>
      <link href="https://realpython.com/courses/working-dict-attributes/"/>
      <updated>2025-08-12T14:00:00+00:00</updated>
      <summary>Explore Python&#x27;s .__dict__ attribute to manage class and instance attributes directly for more flexible, low-level control of your objects.</summary>
      <content type="html">
        &lt;p&gt;Python&amp;rsquo;s &lt;code&gt;.__dict__&lt;/code&gt; is a special attribute in classes and instances that acts as a namespace, mapping attribute names to their corresponding values. You can use &lt;code&gt;.__dict__&lt;/code&gt; to inspect, modify, add, or delete attributes dynamically, which makes it a versatile tool for metaprogramming and debugging.&lt;/p&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll learn about using &lt;code&gt;.__dict__&lt;/code&gt; in various contexts, including classes, instances, and functions. You&amp;rsquo;ll also explore its role in inheritance with practical examples and comparisons to other tools for manipulating attributes.&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;&lt;code&gt;.__dict__&lt;/code&gt;&lt;/strong&gt; holds an object&amp;rsquo;s &lt;strong&gt;writable attributes&lt;/strong&gt;, allowing for dynamic manipulation and introspection.&lt;/li&gt;
&lt;li&gt;Both &lt;strong&gt;&lt;code&gt;vars()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;.__dict__&lt;/code&gt;&lt;/strong&gt; let you &lt;strong&gt;inspect&lt;/strong&gt; an object&amp;rsquo;s attributes. The &lt;code&gt;.__dict__&lt;/code&gt; attribute gives you direct access to the object&amp;rsquo;s namespace, while the &lt;code&gt;vars()&lt;/code&gt; function returns the object&amp;rsquo;s &lt;code&gt;.__dict__&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Common use cases of &lt;code&gt;.__dict__&lt;/code&gt; include &lt;strong&gt;dynamic attribute management&lt;/strong&gt;, &lt;strong&gt;introspection&lt;/strong&gt;, &lt;strong&gt;serialization&lt;/strong&gt;, and &lt;strong&gt;debugging&lt;/strong&gt; in Python applications.&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>Python 3.14 Release Candidate Lands: Faster Code, Smarter Concurrency</title>
      <id>https://realpython.com/python-news-august-2025/</id>
      <link href="https://realpython.com/python-news-august-2025/"/>
      <updated>2025-08-11T14:00:00+00:00</updated>
      <summary>Python 3.14 enters its release candidate phase, Django turns 20, and exciting updates about tools, libraries, and the Python community.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Last month, &lt;strong&gt;Python 3.14&lt;/strong&gt; reached its first release candidate, pushing the interpreter past beta and onto the home stretch toward its final release on October 7. But that headline was only the start—new library releases also landed, Django celebrated its 20th birthday, and EuroPython brought the community together in Prague.&lt;/p&gt;
&lt;p&gt;What follows is a quick-read digest of everything that mattered, from core-language breakthroughs to tooling upgrades and community milestones. Feel free to skip straight to whatever interests you most.&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;h3 id=&quot;python-314-hits-its-first-release-candidate&quot;&gt;Python 3.14 Hits Its First Release Candidate&lt;a class=&quot;headerlink&quot; href=&quot;#python-314-hits-its-first-release-candidate&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Last month’s biggest headline is the release of &lt;a href=&quot;https://www.python.org/downloads/release/python-3140rc1/&quot;&gt;Python 3.14.0rc1&lt;/a&gt;, the first candidate for Python 3.14. This marks the penultimate step before the final release, which is scheduled for October 7, 2025.&lt;/p&gt;
&lt;p&gt;Core developers are now focused on final documentation updates, while library maintainers are encouraged to test their projects with 3.14 and publish &lt;a href=&quot;/ref/glossary/wheel/&quot; class=&quot;ref-link&quot;&gt;wheels&lt;/a&gt; to the &lt;a href=&quot;/ref/glossary/pypi/&quot; class=&quot;ref-link&quot;&gt;Python Package Index (PyPI)&lt;/a&gt;. Since this is a release candidate, there will be no further ABI changes, meaning that &lt;a href=&quot;https://realpython.com/python-wheels/&quot;&gt;wheels&lt;/a&gt; built for this version will work with the final release.&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 the context of Python, ABI (Application Binary Interface) refers to the low-level binary compatibility between compiled Python extension modules and the &lt;a href=&quot;/ref/glossary/cpython/&quot; class=&quot;ref-link&quot;&gt;CPython&lt;/a&gt; &lt;a href=&quot;/ref/glossary/interpreter/&quot; class=&quot;ref-link&quot;&gt;interpreter&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Python 3.14 comes with some exciting new features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#pep-779-free-threaded-python-is-officially-supported&quot;&gt;Free-threaded Python&lt;/a&gt; is now officially supported and no longer experimental.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-pep649&quot;&gt;Deferred evaluation of type annotations&lt;/a&gt; improves type hint semantics.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-pep750&quot;&gt;Template string literals (t-strings)&lt;/a&gt; provide new ways to process custom strings.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-pep734&quot;&gt;Multiple interpreters in the standard library&lt;/a&gt; support a human-friendly concurrency model and true multi-core parallelism.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#pep-784-adding-zstandard-to-the-standard-library&quot;&gt;new &lt;code&gt;compression.zstd&lt;/code&gt; module&lt;/a&gt; in the standard library adds support for Zstandard compression.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Topping the feature list is &lt;strong&gt;free-threaded Python&lt;/strong&gt;, a long-awaited improvement that ushers in the &lt;a href=&quot;https://realpython.com/python-news-july-2025/&quot;&gt;free‑threaded era&lt;/a&gt;. The officially supported free‑threaded build lifts the long‑standing &lt;a href=&quot;/ref/glossary/gil/&quot; class=&quot;ref-link&quot;&gt;Global Interpreter Lock (GIL)&lt;/a&gt;, allowing &lt;a href=&quot;/ref/glossary/cpu-bound-task/&quot; class=&quot;ref-link&quot;&gt;CPU-bound&lt;/a&gt; threads to run truly in parallel on separate cores. As a result, data‑science workloads, web servers, and other &lt;a href=&quot;/ref/glossary/concurrency/&quot; class=&quot;ref-link&quot;&gt;concurrency&lt;/a&gt;‑heavy apps can scale more cleanly without resorting to multiprocessing.&lt;/p&gt;
&lt;p&gt;Existing single‑threaded code keeps working unchanged, but projects that embrace the new model can expect simpler concurrency patterns and better performance.&lt;/p&gt;
&lt;p&gt;Other refinements include improved error messages, enhanced &lt;a href=&quot;/ref/glossary/debugging/&quot; class=&quot;ref-link&quot;&gt;debugging&lt;/a&gt; tools, and new command-line interface (CLI) features for &lt;a href=&quot;https://realpython.com/async-io-python/&quot;&gt;&lt;code&gt;asyncio&lt;/code&gt;&lt;/a&gt; introspection.&lt;/p&gt;
&lt;p&gt;The release also includes &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#binary-releases-for-the-experimental-just-in-time-compiler&quot;&gt;experimental just-in-time (JIT) compilation&lt;/a&gt; in the official macOS and Windows binaries, and a new Windows install manager that can be downloaded from the &lt;a href=&quot;https://apps.microsoft.com/detail/9NQ7512CXL7T&quot;&gt;Microsoft Store&lt;/a&gt;.&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;The latest batch of releases brings fresh updates across the Python ecosystem, from cutting-edge data science libraries to faster installers and frameworks. Whether you’re looking for better performance, smarter &lt;a href=&quot;/ref/glossary/api/&quot; class=&quot;ref-link&quot;&gt;APIs&lt;/a&gt;, or new tools for your workflow, these updates have something for every Pythonista. Here are the key highlights you won’t want to miss.&lt;/p&gt;
&lt;h3 id=&quot;pypy-7320-brings-bug-fixes-and-cython-compatibility&quot;&gt;PyPy 7.3.20 Brings Bug Fixes and Cython Compatibility&lt;a class=&quot;headerlink&quot; href=&quot;#pypy-7320-brings-bug-fixes-and-cython-compatibility&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-august-2025/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-august-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 #260: Harnessing the Power of Python Polars</title>
      <id>https://realpython.com/podcasts/rpp/260/</id>
      <link href="https://realpython.com/podcasts/rpp/260/"/>
      <updated>2025-08-08T12:00:00+00:00</updated>
      <summary>What are the advantages of using Polars for your Python data projects? When should you use the lazy or eager APIs, and what are the benefits of each? This week on the show, we speak with Jeroen Janssens and Thijs Nieuwdorp about their new book, _Python Polars: The Definitive Guide_.</summary>
      <content type="html">
        &lt;p&gt;What are the advantages of using Polars for your Python data projects? When should you use the lazy or eager APIs, and what are the benefits of each? This week on the show, we speak with Jeroen Janssens and Thijs Nieuwdorp about their new book, _Python Polars: The Definitive Guide_.&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: Python Basics: Setting Up Python</title>
      <id>https://realpython.com/quizzes/setting-up-python/</id>
      <link href="https://realpython.com/quizzes/setting-up-python/"/>
      <updated>2025-08-08T12:00:00+00:00</updated>
      <summary>Test your knowledge of installing Python on Windows, macOS, and Ubuntu, setting PATH, and using IDLE with this quick quiz.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you will review the key steps for installing Python on Windows, macOS, and Ubuntu Linux. You will recall what the PATH environment variable is for, and what Python distribution to choose.&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 explanations in the questions will link back to the &lt;em&gt;Windows&lt;/em&gt; installation lesson, but all question are kept general, so you&amp;rsquo;ll be able to answer them independent of which operating system you use.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You&amp;rsquo;ll also revisit how to use IDLE, and enter commands at the Python prompt. Brush up on these essentials before you start the quiz by reviewing &lt;a href=&quot;https://realpython.com/courses/setting-up-python/&quot;&gt;Setting Up 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>What Are Mixin Classes in Python?</title>
      <id>https://realpython.com/python-mixin/</id>
      <link href="https://realpython.com/python-mixin/"/>
      <updated>2025-08-06T14:00:00+00:00</updated>
      <summary>Learn how to use Python mixin classes to write modular, reusable, and flexible code with practical examples and design tips.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Mixins offer a powerful way to reuse code across multiple Python classes without forcing them into a rigid inheritance hierarchy. Instead of building deep and brittle class trees, you can use mixins to share common behaviors in a modular and flexible way. Learn when and how to implement mixin classes effectively in your Python projects.&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;Mixins&lt;/strong&gt; allow you to add isolated, reusable functionalities to classes without enforcing a strict type hierarchy.&lt;/li&gt;
&lt;li&gt;Python has &lt;strong&gt;no dedicated syntax&lt;/strong&gt; for declaring mixins. You create mixins by defining &lt;strong&gt;classes&lt;/strong&gt; with specific behaviors that other classes can inherit without forming an &lt;em&gt;is-a&lt;/em&gt; relationship.&lt;/li&gt;
&lt;li&gt;Mixins rely on &lt;strong&gt;multiple inheritance&lt;/strong&gt; to combine features from different classes, enhancing flexibility and code reuse.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stateful mixins&lt;/strong&gt; require careful design to manage instance attributes and avoid conflicts with other classes.&lt;/li&gt;
&lt;li&gt;Python’s &lt;strong&gt;method resolution order (MRO)&lt;/strong&gt; determines the order in which classes are inherited, affecting how mixins are applied.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should have a good understanding of &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming (OOP)&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/solid-principles-python/&quot;&gt;SOLID principles&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;inheritance&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;Python classes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So, what is a Python mixin, and when should you use one?&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-mixin-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-mixin-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 mixin classes 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.770597e4ea96.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 Are Mixin Classes 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-mixin/&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: #e5c6aa;&quot; alt=&quot;What Are Mixin Classes in Python?&quot; src=&quot;https://files.realpython.com/media/Multiple-Inheritance-and-Mixins_Watermarked.1cfef28a6113.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Multiple-Inheritance-and-Mixins_Watermarked.1cfef28a6113.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Multiple-Inheritance-and-Mixins_Watermarked.1cfef28a6113.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Multiple-Inheritance-and-Mixins_Watermarked.1cfef28a6113.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Multiple-Inheritance-and-Mixins_Watermarked.1cfef28a6113.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.770597e4ea96.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-mixin/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;What Are Mixin Classes in Python?&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your knowledge of Python mixins—specialized classes that let you reuse methods without traditional inheritance.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;in-short-mixins-encapsulate-reusable-behaviors&quot;&gt;In Short: Mixins Encapsulate Reusable Behaviors&lt;a class=&quot;headerlink&quot; href=&quot;#in-short-mixins-encapsulate-reusable-behaviors&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming (OOP)&lt;/a&gt;, a mixin is a tool that allows you to reuse a common piece of functionality across several, often unrelated data types while keeping them &lt;a href=&quot;https://en.wikipedia.org/wiki/Loose_coupling&quot;&gt;loosely coupled&lt;/a&gt;. In practical terms, mixins can help you achieve a cleaner design with more flexible code consisting of modular and composable pieces.&lt;/p&gt;
&lt;p&gt;Many programming languages, including Ruby, Dart, and Scala, support this pattern explicitly through specialized syntax and &lt;a href=&quot;https://realpython.com/python-keywords/&quot;&gt;keywords&lt;/a&gt;. Others let you simulate mixins with existing constructs, such as &lt;a href=&quot;https://www.baeldung.com/java-static-default-methods&quot;&gt;default method implementations&lt;/a&gt; in Java interfaces. Conversely, Python relies on &lt;a href=&quot;https://en.wikipedia.org/wiki/Multiple_inheritance&quot;&gt;multiple inheritance&lt;/a&gt; as the underlying mechanism to facilitate the same concept.&lt;/p&gt;
&lt;p&gt;Python mixins are ordinary &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt; with a special meaning. You use them to give other classes new superpowers or to modify their current behavior without forming a rigid type hierarchy. Mixins can also act as a form of &lt;a href=&quot;https://en.wikipedia.org/wiki/Dependency_injection&quot;&gt;dependency injection&lt;/a&gt;, allowing you to customize code beyond your control, for example, by plugging into a third-party library or framework.&lt;/p&gt;
&lt;p&gt;To give you an idea of when &lt;strong&gt;mixin classes&lt;/strong&gt; are most useful, imagine that you wanted to represent arbitrary Python objects with different data formats. Implementing the same &lt;a href=&quot;https://realpython.com/python-serialize-data/&quot;&gt;serialization&lt;/a&gt; logic in each class would lead to &lt;a href=&quot;https://en.wikipedia.org/wiki/Duplicate_code&quot;&gt;duplicate code&lt;/a&gt;, which is a well-known &lt;a href=&quot;https://en.wikipedia.org/wiki/Code_smell&quot;&gt;code smell&lt;/a&gt; that violates the &lt;a href=&quot;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&quot;&gt;DRY principle&lt;/a&gt;:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/diag1.366487128ad3.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/diag1.366487128ad3.png&quot; width=&quot;1280&quot; height=&quot;306&quot; srcset=&quot;/cdn-cgi/image/width=320,format=auto/https://files.realpython.com/media/diag1.366487128ad3.png 320w, /cdn-cgi/image/width=426,format=auto/https://files.realpython.com/media/diag1.366487128ad3.png 426w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/diag1.366487128ad3.png 640w, /cdn-cgi/image/width=1280,format=auto/https://files.realpython.com/media/diag1.366487128ad3.png 1280w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Class Diagram of Duplicated Serialization Logic&quot; data-asset=&quot;6443&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Class Diagram Showing Duplicated Serialization Logic&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;Notice the repeated &lt;code&gt;.serialize()&lt;/code&gt; method, which appears across all classes in the &lt;a href=&quot;https://en.wikipedia.org/wiki/Class_diagram&quot;&gt;UML class diagram&lt;/a&gt; above. You can fix this issue by extracting the shared functionality into a common &lt;a href=&quot;/ref/glossary/base-class/&quot; class=&quot;ref-link&quot;&gt;base class&lt;/a&gt; and creating the following inheritance hierarchy:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/diag2.a4d4c85b9829.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/diag2.a4d4c85b9829.png&quot; width=&quot;1280&quot; height=&quot;890&quot; srcset=&quot;/cdn-cgi/image/width=320,format=auto/https://files.realpython.com/media/diag2.a4d4c85b9829.png 320w, /cdn-cgi/image/width=426,format=auto/https://files.realpython.com/media/diag2.a4d4c85b9829.png 426w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/diag2.a4d4c85b9829.png 640w, /cdn-cgi/image/width=1280,format=auto/https://files.realpython.com/media/diag2.a4d4c85b9829.png 1280w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Class Diagram of an Awkward Inheritance Hierarchy&quot; data-asset=&quot;6444&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Class Diagram of an Awkward Inheritance Hierarchy&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;But now you end up with an awkward inheritance hierarchy where animals and vehicles share a common ancestor. You’ve grouped them under a shared interface for structural reasons, while they conceptually belong to entirely different categories.&lt;/p&gt;
&lt;p&gt;Moreover, a design centered around &lt;a href=&quot;/ref/glossary/inheritance/&quot; class=&quot;ref-link&quot;&gt;inheritance&lt;/a&gt; can be fragile, making it hard to accommodate future use cases. Maybe you’ll need to implement a &lt;a href=&quot;https://en.wikipedia.org/wiki/Unmanned_aerial_vehicle&quot;&gt;mechanical bird&lt;/a&gt; equipped with a vehicle’s engine and the ability to fly, but without needing to eat or having a &lt;a href=&quot;https://en.wikipedia.org/wiki/Vehicle_identification_number&quot;&gt;VIN&lt;/a&gt; number. As it stands, there’s no straightforward way to fit that kind of data type into your class hierarchy without making inelegant compromises.&lt;/p&gt;
&lt;p&gt;Another issue that sometimes arises from using inheritance is a tendency for &lt;strong&gt;overgeneralization&lt;/strong&gt;. When the base class becomes too broad in scope, &lt;a href=&quot;/ref/glossary/subclass/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;subclasses&lt;/strong&gt;&lt;/a&gt; start to inherit unnecessary features. For example, if a vehicle requires another serialization method, then all animals automatically inherit it, whether they need one or not. This problem was aptly described by &lt;a href=&quot;https://en.wikipedia.org/wiki/Joe_Armstrong_(programmer)&quot;&gt;Joe Armstrong&lt;/a&gt;, the creator of &lt;a href=&quot;https://en.wikipedia.org/wiki/Erlang_(programming_language)&quot;&gt;Erlang&lt;/a&gt;, in an interview for &lt;a href=&quot;https://codersatwork.com/&quot;&gt;&lt;em&gt;Coders at Work&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Because the problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.&lt;/p&gt;
&lt;p&gt;— &lt;em&gt;Joe Armstrong&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A better approach would be to design your types based on what they &lt;em&gt;do&lt;/em&gt; rather than what they &lt;em&gt;are&lt;/em&gt;. This means favoring &lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;composition over inheritance&lt;/a&gt; and delegating responsibilities to smaller, more focused components, promoting &lt;a href=&quot;https://en.wikipedia.org/wiki/Separation_of_concerns&quot;&gt;separation of concerns&lt;/a&gt;:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/diag3.91d1665b3577.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/diag3.91d1665b3577.png&quot; width=&quot;1280&quot; height=&quot;604&quot; srcset=&quot;/cdn-cgi/image/width=320,format=auto/https://files.realpython.com/media/diag3.91d1665b3577.png 320w, /cdn-cgi/image/width=426,format=auto/https://files.realpython.com/media/diag3.91d1665b3577.png 426w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/diag3.91d1665b3577.png 640w, /cdn-cgi/image/width=1280,format=auto/https://files.realpython.com/media/diag3.91d1665b3577.png 1280w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Explosion of Classes Due to Composition&quot; data-asset=&quot;6445&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Explosion of Classes Due to Composition&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;Compared to the inheritance-based version, this diagram looks much more intimidating due to the greater number of individual components. On the other hand, such a fine-grained design allows you to compose behaviors in novel ways, which could’ve been difficult to anticipate during the initial requirements analysis.&lt;/p&gt;
&lt;p&gt;Wouldn’t it be ideal to combine the convenience of inheritance with the flexibility of composition? That’s precisely where mixins shine! Now that you understand the broader context, it’s time to dig a little deeper by answering more specific questions about mixins.&lt;/p&gt;
&lt;h2 id=&quot;how-can-you-recognize-a-mixin-class-in-the-wild&quot;&gt;How Can You Recognize a Mixin Class in the Wild?&lt;a class=&quot;headerlink&quot; href=&quot;#how-can-you-recognize-a-mixin-class-in-the-wild&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;For starters, here’s a straightforward example of a mixin class defined in Python:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-mixin/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-mixin/ »&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 Are Mixin Classes in Python?</title>
      <id>https://realpython.com/quizzes/python-mixin/</id>
      <link href="https://realpython.com/quizzes/python-mixin/"/>
      <updated>2025-08-06T12:00:00+00:00</updated>
      <summary>Test your knowledge of Python mixins—specialized classes that let you reuse methods without traditional inheritance.</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-mixin/&quot;&gt;What Are Mixin Classes in Python?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit Python mixins, how they&amp;rsquo;re used, and the benefits they offer.&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 T-Strings</title>
      <id>https://realpython.com/courses/exploring-t-strings/</id>
      <link href="https://realpython.com/courses/exploring-t-strings/"/>
      <updated>2025-08-05T14: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;p&gt;Python 3.14&amp;rsquo;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&amp;rsquo;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 video course, you&amp;rsquo;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;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>Skip Ahead in Loops With Python&#x27;s Continue Keyword</title>
      <id>https://realpython.com/python-continue/</id>
      <link href="https://realpython.com/python-continue/"/>
      <updated>2025-08-04T14:00:00+00:00</updated>
      <summary>Learn how Python&#x27;s continue statement works, when to use it, common mistakes to avoid, and what happens under the hood in CPython byte code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;continue&lt;/code&gt; keyword functions as a statement that controls the flow of a loop. It allows you to skip code in a loop for the current iteration and jump immediately to the next one. It’s used exclusively in &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; loops, letting you control the flow of execution, bypass specific conditions, and continue processing in a structured and predictable way.&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;Executing &lt;code&gt;continue&lt;/code&gt; &lt;strong&gt;doesn’t affect the &lt;code&gt;else&lt;/code&gt; clause&lt;/strong&gt; of a loop.&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;continue&lt;/code&gt; incorrectly may result in &lt;strong&gt;skipping necessary code&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can’t use &lt;code&gt;continue&lt;/code&gt; in a function or class that’s nested in a loop.&lt;/li&gt;
&lt;li&gt;On a &lt;strong&gt;bytecode level&lt;/strong&gt;, &lt;code&gt;continue&lt;/code&gt; executes the same instructions as reaching the end of a loop.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Armed with this knowledge, you’ll be able to confidently write loops using &lt;code&gt;continue&lt;/code&gt; and expand your skills as a Python programmer.&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-continue-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-continue-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 skip ahead in loops with Python’s continue keyword .&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.770597e4ea96.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 “Skip Ahead in Loops With Python&#x27;s Continue Keyword” 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-continue/&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;Skip Ahead in Loops With Python&#x27;s Continue Keyword&quot; src=&quot;https://files.realpython.com/media/Skip-Ahead-in-Loops-with-Pythons-Continue-Keyword_Watermarked.dd2520b4a034.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Skip-Ahead-in-Loops-with-Pythons-Continue-Keyword_Watermarked.dd2520b4a034.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Skip-Ahead-in-Loops-with-Pythons-Continue-Keyword_Watermarked.dd2520b4a034.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Skip-Ahead-in-Loops-with-Pythons-Continue-Keyword_Watermarked.dd2520b4a034.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Skip-Ahead-in-Loops-with-Pythons-Continue-Keyword_Watermarked.dd2520b4a034.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.770597e4ea96.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-continue/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Skip Ahead in Loops With Python&#x27;s Continue Keyword&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Test your understanding of Python&#x27;s continue keyword, which allows you to skip code in a loop for the current iteration and jump immediately to the next one.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;pythons-continue-keyword&quot;&gt;Python’s &lt;code&gt;continue&lt;/code&gt; Keyword&lt;a class=&quot;headerlink&quot; href=&quot;#pythons-continue-keyword&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Loops are &lt;a href=&quot;https://realpython.com/python-control-flow/&quot;&gt;control flow statements&lt;/a&gt; used to perform operations repeatedly a certain number of times. In a normal loop, the loop body runs from start to finish, with the number of iterations controlled by the type of loop:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt; runs a specific number of times and is usually used to process a collection of data.&lt;/li&gt;
&lt;li&gt;A &lt;a href=&quot;https://realpython.com/python-while-loop/&quot;&gt;&lt;code&gt;while&lt;/code&gt; loop&lt;/a&gt; runs as long as a specific condition evaluates to &lt;a href=&quot;/ref/keywords/true/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;True&lt;/code&gt;&lt;/a&gt;. When the condition evaluates to &lt;a href=&quot;/ref/keywords/false/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;False&lt;/code&gt;&lt;/a&gt;, the loop ends.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In both cases, you may find it useful to stop the execution of the loop body and move to the next iteration. The way to do that is with the &lt;a href=&quot;/ref/keywords/continue/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;&lt;code&gt;continue&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; keyword.&lt;/p&gt;
&lt;p&gt;In any loop, &lt;code&gt;continue&lt;/code&gt; stops the code currently executing, and jumps immediately back to the top of the loop, skipping to the next iteration.&lt;/p&gt;
&lt;h3 id=&quot;understanding-its-behavior-in-for-and-while-loops&quot;&gt;Understanding Its Behavior in &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; Loops&lt;a class=&quot;headerlink&quot; href=&quot;#understanding-its-behavior-in-for-and-while-loops&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In a &lt;a href=&quot;/ref/keywords/for/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;for&lt;/code&gt;&lt;/a&gt; loop, &lt;code&gt;continue&lt;/code&gt; moves the &lt;a href=&quot;/ref/glossary/iterator/&quot; class=&quot;ref-link&quot;&gt;iterator&lt;/a&gt; to the next item to be processed. If no other items are available, then the loop ends.&lt;/p&gt;
&lt;p&gt;Assume you have the following &lt;code&gt;for&lt;/code&gt; loop that computes the sum of all numbers in a list:&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;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&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;total&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.770597e4ea96.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.770597e4ea96.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;This works fine, but what if you want to add only the &lt;em&gt;positive&lt;/em&gt; numbers, ignoring all the negative ones? You can modify this loop to add only positive numbers using &lt;code&gt;continue&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;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;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;hll&quot;&gt;        &lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt;
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&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;total&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.770597e4ea96.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.770597e4ea96.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 case, since Python executes &lt;code&gt;continue&lt;/code&gt; only when the number is less than zero, it doesn’t add those numbers to &lt;code&gt;total&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You’ve seen how the &lt;code&gt;continue&lt;/code&gt; statement works in a &lt;code&gt;for&lt;/code&gt; loop—now you’ll see it working similarly in a &lt;a href=&quot;/ref/keywords/while/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;while&lt;/code&gt;&lt;/a&gt; loop.&lt;/p&gt;
&lt;p&gt;In a &lt;code&gt;while&lt;/code&gt; loop, &lt;code&gt;continue&lt;/code&gt; transfers control back to the condition at the top of the loop. If that condition is &lt;code&gt;True&lt;/code&gt;, then the loop body will run again. If it’s &lt;code&gt;False&lt;/code&gt;, then the loop ends.&lt;/p&gt;
&lt;p&gt;Consider the following &lt;code&gt;while&lt;/code&gt; loop. It leverages Python’s &lt;a href=&quot;https://realpython.com/python-walrus-operator/&quot;&gt;walrus operator&lt;/a&gt; to &lt;a href=&quot;https://realpython.com/python-keyboard-input/&quot;&gt;get user input&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/convert-python-string-to-int/&quot;&gt;casts it to an &lt;code&gt;int&lt;/code&gt;&lt;/a&gt;, and adds the number to a running total. The loop stops when the user enters &lt;code&gt;0&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;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;sum_whole_numbers.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;s2&quot;&gt;&quot;Enter one whole number per input.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&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;s2&quot;&gt;&quot;Type 0 to stop and display their sum:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_int&lt;/span&gt; &lt;span class=&quot;o&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;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;+ &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_int&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;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;=}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&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.770597e4ea96.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.770597e4ea96.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;Again, you only want to add the positive numbers that your users enter, so you modify the loop using &lt;code&gt;continue&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;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;sum_whole_numbers.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;s2&quot;&gt;&quot;Enter one whole number per input.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&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;s2&quot;&gt;&quot;Type 0 to stop and display their sum:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_int&lt;/span&gt; &lt;span class=&quot;o&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;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;+ &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;hll&quot;&gt;        &lt;span class=&quot;k&quot;&gt;continue&lt;/span&gt;
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_int&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;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;=}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&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.770597e4ea96.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.770597e4ea96.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 can copy the code and try it out. When you &lt;a href=&quot;https://realpython.com/run-python-scripts/&quot;&gt;run the script&lt;/a&gt;, Python keeps prompting you for input until you enter &lt;code&gt;0&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-continue/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-continue/ »&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 #259: Design Patterns That Don&#x27;t Translate to Python</title>
      <id>https://realpython.com/podcasts/rpp/259/</id>
      <link href="https://realpython.com/podcasts/rpp/259/"/>
      <updated>2025-08-01T12:00:00+00:00</updated>
      <summary>Do the design patterns learned in other programming languages translate to coding in Python? 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;Do the design patterns learned in other programming languages translate to coding in Python? 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>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.770597e4ea96.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.770597e4ea96.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.770597e4ea96.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.770597e4ea96.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>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>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>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>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>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>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>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>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>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>
  

</feed>
