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

  
    <entry>
      <title>The Real Python Podcast – Episode #247: Exploring DuckDB &amp; Comparing Python Expressions vs Statements</title>
      <id>https://realpython.com/podcasts/rpp/247/</id>
      <link href="https://realpython.com/podcasts/rpp/247/"/>
      <updated>2025-04-18T12:00:00+00:00</updated>
      <summary>Are you looking for a fast database that can handle large datasets in Python? What&#x27;s the difference between a Python expression and a statement? 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;Are you looking for a fast database that can handle large datasets in Python? What&#x27;s the difference between a Python expression and a statement? 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>How to Exit Loops Early With the Python Break Keyword</title>
      <id>https://realpython.com/python-break/</id>
      <link href="https://realpython.com/python-break/"/>
      <updated>2025-04-16T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll explore various ways to use Python&#x27;s break statement to exit a loop early. Through practical examples, such as a student test score analysis tool and a number-guessing game, you&#x27;ll see how the break statement can improve the efficiency and effectiveness of your code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In Python, the &lt;a href=&quot;/ref/keywords/break/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;break&lt;/code&gt; statement&lt;/a&gt; lets you exit a loop prematurely, transferring control to the code that follows the loop. This tutorial guides you through using &lt;code&gt;break&lt;/code&gt; in both &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; loops. You’ll also briefly explore the &lt;code&gt;continue&lt;/code&gt; keyword, which complements &lt;code&gt;break&lt;/code&gt; by skipping the current loop iteration.&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;A &lt;code&gt;break&lt;/code&gt; in Python&lt;/strong&gt; is a keyword that lets you exit a loop immediately, stopping further iterations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Using &lt;code&gt;break&lt;/code&gt; outside of loops&lt;/strong&gt; doesn’t make sense because it’s specifically designed to exit loops early.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The &lt;code&gt;break&lt;/code&gt; doesn’t exit all loops&lt;/strong&gt;, only the innermost loop that contains it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To explore the use of &lt;code&gt;break&lt;/code&gt; in Python, you’ll determine if a student needs tutoring based on the number of failed test scores. Then, you’ll print out a given number of test scores and calculate how many students failed at least one test.&lt;/p&gt;
&lt;p&gt;You’ll also take a brief detour from this main scenario to examine how you can use &lt;code&gt;break&lt;/code&gt; statements to accept and process user input, using a number-guessing game.&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-break-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-break-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 exit loops early with the Python break 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.6eec2e95bede.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 Exit Loops Early With the Python Break 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-break/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe0e6;&quot; alt=&quot;How to Exit Loops Early With the Python Break Keyword&quot; src=&quot;https://files.realpython.com/media/Exit-Loops-Early-With-Pythons-Break-Keyword_Watermarked.3d61a543d1f4.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Exit-Loops-Early-With-Pythons-Break-Keyword_Watermarked.3d61a543d1f4.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Exit-Loops-Early-With-Pythons-Break-Keyword_Watermarked.3d61a543d1f4.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Exit-Loops-Early-With-Pythons-Break-Keyword_Watermarked.3d61a543d1f4.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Exit-Loops-Early-With-Pythons-Break-Keyword_Watermarked.3d61a543d1f4.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.6eec2e95bede.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-break/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;How to Exit Loops Early With the Python Break Keyword&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 Python break statement. This keyword allows you to exit a loop prematurely, transferring control to the code that follows the loop.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;introducing-the-break-statement&quot;&gt;Introducing the &lt;code&gt;break&lt;/code&gt; Statement&lt;a class=&quot;headerlink&quot; href=&quot;#introducing-the-break-statement&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before proceeding to the main examples, here’s a basic explanation of what the &lt;code&gt;break&lt;/code&gt; statement is and what it does. It’s a Python keyword that, when used in a loop, immediately exits the loop and transfers control to the code that would normally run after the loop’s standard conclusion.&lt;/p&gt;
&lt;p&gt;You can see the basics of the &lt;code&gt;break&lt;/code&gt; statement in a simple example. The following code demonstrates a loop that prints numbers within a range until the next number is greater than 5:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;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;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
&lt;span class=&quot;gp&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;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;5&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.6eec2e95bede.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.6eec2e95bede.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 short code example consists of a &lt;a href=&quot;/ref/keywords/for/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt; that iterates through a range of numbers from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;9&lt;/code&gt;. It &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;prints&lt;/a&gt; out each number, but when the next number is greater than &lt;code&gt;5&lt;/code&gt;, a &lt;code&gt;break&lt;/code&gt; statement terminates the loop early. So, this code will print the numbers from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;5&lt;/code&gt;, and then the loop will end.&lt;/p&gt;
&lt;p&gt;As &lt;code&gt;break&lt;/code&gt; statements end loops early, it wouldn’t make sense for you to use them in any context that doesn’t involve a loop. In fact, Python will raise a &lt;a href=&quot;https://realpython.com/invalid-syntax-python/&quot;&gt;&lt;code&gt;SyntaxError&lt;/code&gt;&lt;/a&gt; if you try to use a &lt;code&gt;break&lt;/code&gt; statement outside of a loop.&lt;/p&gt;
&lt;p&gt;A key benefit of using &lt;code&gt;break&lt;/code&gt; statements is that you can prevent unnecessary loop iterations by exiting early when appropriate. You’ll see this in action in the next section.&lt;/p&gt;
&lt;h2 id=&quot;breaking-out-of-a-loop-with-a-set-number-of-iterations&quot;&gt;Breaking Out of a Loop With a Set Number of Iterations&lt;a class=&quot;headerlink&quot; href=&quot;#breaking-out-of-a-loop-with-a-set-number-of-iterations&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Imagine you’re a teacher who evaluates the scores of your students. Based on the scores, you want to determine how many tests each student has failed. The following example demonstrates how you might accomplish this task using a &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt; to iterate through the students’ test scores:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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;scores&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;mi&quot;&gt;90&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;70&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;85&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;35&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&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;num_failed_scores&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;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;failed_score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;score&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scores&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;score&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;failed_score&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;num_failed_scores&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;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;Number of failed tests: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num_failed_scores&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;span class=&quot;go&quot;&gt;Number of failed tests: 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.6eec2e95bede.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.6eec2e95bede.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-break/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-break/ »&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 Exit Loops Early With the Python Break Keyword</title>
      <id>https://realpython.com/quizzes/python-break/</id>
      <link href="https://realpython.com/quizzes/python-break/"/>
      <updated>2025-04-16T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of the Python break statement. This keyword allows you to exit a loop prematurely, transferring control to the code that follows the loop.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the Python &lt;a href=&quot;https://realpython.com/python-break/&quot;&gt;&lt;code&gt;break&lt;/code&gt; statement&lt;/a&gt;.
This keyword allows you to exit a loop prematurely, transferring control to the code that follows the loop.&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>Creating a Python Dice Roll Application</title>
      <id>https://realpython.com/courses/creating-dice-roll-application/</id>
      <link href="https://realpython.com/courses/creating-dice-roll-application/"/>
      <updated>2025-04-15T14:00:00+00:00</updated>
      <summary>In this step-by-step video course, you&#x27;ll build a dice-rolling simulator app with a minimal text-based user interface using Python. The app will simulate the rolling of up to six dice. Each individual die will have six sides.</summary>
      <content type="html">
        &lt;p&gt;In this video course, you&amp;rsquo;ll learn how to create a Python dice roll simulator. The course guides you through building a text-based user interface (TUI) application that simulates rolling dice using Python&amp;rsquo;s &lt;code&gt;random&lt;/code&gt; module. You&amp;rsquo;ll learn to gather and validate user input, use &lt;code&gt;random.randint()&lt;/code&gt; for dice rolling, and display results with ASCII art.&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;To simulate &lt;strong&gt;dice-rolling&lt;/strong&gt; events, you can use &lt;strong&gt;&lt;code&gt;random.randint()&lt;/code&gt;&lt;/strong&gt; .&lt;/li&gt;
&lt;li&gt;To get the &lt;strong&gt;user&amp;rsquo;s input&lt;/strong&gt;, you use the built-in &lt;strong&gt;&lt;code&gt;input()&lt;/code&gt;&lt;/strong&gt; function.&lt;/li&gt;
&lt;li&gt;To display dice in Python, you generate &lt;strong&gt;ASCII art representations&lt;/strong&gt; of dice faces and use &lt;strong&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To manipulate &lt;strong&gt;strings&lt;/strong&gt;, you use methods such as &lt;strong&gt;&lt;code&gt;.center()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;.join()&lt;/code&gt;&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>Namespaces in Python</title>
      <id>https://realpython.com/python-namespace/</id>
      <link href="https://realpython.com/python-namespace/"/>
      <updated>2025-04-14T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about Python namespaces, the structures that store and organize the symbolic names during the execution of a Python program. You&#x27;ll learn when namespaces are created, how they&#x27;re implemented, and how they support variable scope.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;A Python &lt;strong&gt;namespace&lt;/strong&gt; is a mapping from names to objects. It works like a dictionary where keys are object names and values are the objects themselves. Namespaces organize variables and functions in a dedicated space, allowing you to use multiple instances of the same name without conflict, as long as they’re in different namespaces.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll explore the different types of namespaces in Python, including the built-in, global, local, and enclosing namespaces. You’ll also learn how they define the scope of names and influence name resolution in Python programs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Python &lt;strong&gt;namespaces&lt;/strong&gt; serve as containers that &lt;strong&gt;map names to objects&lt;/strong&gt;, allowing for organized access and management of variables, functions, classes, and objects in general.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Namespace and scope&lt;/strong&gt; differ in that a namespace maps names to objects, while a scope is the &lt;strong&gt;region of code&lt;/strong&gt; where you can access a name.&lt;/li&gt;
&lt;li&gt;Python &lt;strong&gt;implements&lt;/strong&gt; most namespaces using &lt;strong&gt;dictionaries&lt;/strong&gt;, where each namespace’s lifecycle is tied to the execution context, such as global or local scopes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding how namespaces work will improve your ability to manage and organize code efficiently in Python programs, helping to prevent name conflicts and other issues. To get the most out of this tutorial, you should be familiar with Python &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;. Knowledge of &lt;a href=&quot;https://realpython.com/inner-functions-what-are-they-good-for/&quot;&gt;inner functions&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-closure/&quot;&gt;closures&lt;/a&gt; will also be a plus.&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-namespaces-scope-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-namespaces-scope-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 namespaces and scope 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.6eec2e95bede.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 “Namespaces 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-namespace/&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;Namespaces and Scopes in Python&quot; src=&quot;https://files.realpython.com/media/UPDATE-Namespaces-and-Scope-in-Python_Watermarked.0597679893f1.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/UPDATE-Namespaces-and-Scope-in-Python_Watermarked.0597679893f1.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/UPDATE-Namespaces-and-Scope-in-Python_Watermarked.0597679893f1.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/UPDATE-Namespaces-and-Scope-in-Python_Watermarked.0597679893f1.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/UPDATE-Namespaces-and-Scope-in-Python_Watermarked.0597679893f1.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.6eec2e95bede.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-namespace/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Namespaces 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 Python namespaces. These concepts are crucial for organizing the symbolic names assigned to objects in a Python program and ensuring they don&#x27;t interfere with one another.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-namespaces-in-python&quot;&gt;Getting to Know Namespaces in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-namespaces-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A &lt;a href=&quot;/ref/glossary/namespace/&quot; class=&quot;ref-link&quot;&gt;namespace&lt;/a&gt; is a container that holds the currently defined symbolic names and the objects each name references. You can think of a namespace as a &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt;, in which the keys are object names and the values are the objects themselves. Each key-value pair maps a name to its corresponding object.&lt;/p&gt;
&lt;p&gt;Namespaces let you use the same name in different contexts without collisions. It’s like giving everything its own little room in a well-organized house. They allow Python to keep things organized, prevent naming conflicts, support the concept of &lt;a href=&quot;#understanding-the-scope-of-names&quot;&gt;scope&lt;/a&gt;, and enforce modularity.&lt;/p&gt;
&lt;p&gt;Namespaces are so crucial in Python that they were immortalized in &lt;a href=&quot;https://realpython.com/zen-of-python/&quot;&gt;The Zen of Python&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Namespaces are one honking great idea—let’s do more of those!&lt;/p&gt;
&lt;p&gt;— &lt;em&gt;Tim Peters&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As Tim Peters suggests, namespaces aren’t just great. They’re &lt;em&gt;honking&lt;/em&gt; great, and Python uses them extensively. Depending on how you structure your code, a Python program can have up to four different types of namespaces:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Built-In&lt;/li&gt;
&lt;li&gt;Global&lt;/li&gt;
&lt;li&gt;Local&lt;/li&gt;
&lt;li&gt;Enclosing or nonlocal&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These namespaces have differing lifetimes. As Python executes a program, it creates namespaces as necessary and removes them when it no longer needs them. Typically, many namespaces will exist at any given time.&lt;/p&gt;
&lt;p&gt;The Python global, local, and nonlocal namespaces are implemented as dictionaries. In contrast, the built-in namespace isn’t a dictionary but a module called &lt;code&gt;builtins&lt;/code&gt;. This module acts as the container for the built-in namespace.&lt;/p&gt;
&lt;p&gt;In the following sections, you’ll learn about these four namespaces and what their content and behavior are.&lt;/p&gt;
&lt;h3 id=&quot;the-built-in-namespace&quot;&gt;The Built-in Namespace&lt;a class=&quot;headerlink&quot; href=&quot;#the-built-in-namespace&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;built-in namespace&lt;/strong&gt; contains the names of all of Python’s built-in objects. This namespace is available while the Python &lt;a href=&quot;/ref/glossary/interpreter/&quot; class=&quot;ref-link&quot;&gt;interpreter&lt;/a&gt; is running. So, you can access the names that live in this namespace at any time in your code without explicitly importing them.&lt;/p&gt;
&lt;p&gt;You can list the objects in the built-in namespace with the &lt;a href=&quot;/ref/builtin-functions/dir/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;dir()&lt;/code&gt;&lt;/a&gt; function using the &lt;code&gt;__builtins__&lt;/code&gt; object as an argument:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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;nb&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__builtins__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;ArithmeticError&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;AssertionError&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;AttributeError&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;BaseException&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    ...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;super&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;tuple&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;type&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;vars&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;zip&#x27;&lt;/span&gt;
&lt;span class=&quot;go&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.6eec2e95bede.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.6eec2e95bede.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 may recognize some objects here, such as &lt;a href=&quot;https://realpython.com/python-built-in-exceptions/&quot;&gt;built-in exceptions&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-data-types/#built-in-functions&quot;&gt;built-in functions&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/ref/builtin-types/&quot;&gt;built-in data types&lt;/a&gt;. Python creates the built-in namespace when it starts and keeps it active until the interpreter terminates.&lt;/p&gt;
&lt;h3 id=&quot;the-global-namespace&quot;&gt;The Global Namespace&lt;a class=&quot;headerlink&quot; href=&quot;#the-global-namespace&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;global namespace&lt;/strong&gt; contains the names defined at the module level. Python creates a main global namespace when the main program’s body starts. This namespace remains in existence until the interpreter terminates.&lt;/p&gt;
&lt;p&gt;Additionally, each module has its own global namespace. The interpreter creates a global namespace for any module that your program loads with the &lt;a href=&quot;https://realpython.com/absolute-vs-relative-python-imports/&quot;&gt;&lt;code&gt;import&lt;/code&gt;&lt;/a&gt; statement. For further reading on main functions and modules in Python, see the following resources:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-namespace/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-namespace/ »&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: Namespaces in Python</title>
      <id>https://realpython.com/quizzes/python-namespace/</id>
      <link href="https://realpython.com/quizzes/python-namespace/"/>
      <updated>2025-04-14T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python namespaces. These concepts are crucial for organizing the symbolic names assigned to objects in a Python program and ensuring they don&#x27;t interfere with one another.</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-namespace/&quot;&gt;Namespaces in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll revisit how Python organizes symbolic names and objects in namespaces, when Python creates a new namespace, how namespaces are implemented, and how variable scope determines symbolic name visibility.&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 #246: Learning Intermediate Python With a Deep Dive Course</title>
      <id>https://realpython.com/podcasts/rpp/246/</id>
      <link href="https://realpython.com/podcasts/rpp/246/"/>
      <updated>2025-04-11T12:00:00+00:00</updated>
      <summary>Do you want to learn deeper concepts in Python? Would the accountability of scheduled group classes help you get past the basics? This week, five Real Python Intermediate Deep Dive workshop members discuss their experiences.</summary>
      <content type="html">
        &lt;p&gt;Do you want to learn deeper concepts in Python? Would the accountability of scheduled group classes help you get past the basics? This week, five Real Python Intermediate Deep Dive workshop members discuss their experiences.&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>Using Python&#x27;s .__dict__ to Work With Attributes</title>
      <id>https://realpython.com/python-dict-attribute/</id>
      <link href="https://realpython.com/python-dict-attribute/"/>
      <updated>2025-04-09T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll dive deeper into the .__dict__ attribute in Python objects. This attribute is a dictionary-like object that holds writable class or instance attributes. It allows you to manage attributes at a low level, making your classes flexible and efficient.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’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 tutorial, you’ll learn about using &lt;code&gt;.__dict__&lt;/code&gt; in various contexts, including classes, instances, and functions. You’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 tutorial, you’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’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’s attributes. The &lt;code&gt;.__dict__&lt;/code&gt; attribute gives you direct access to the object’s namespace, while the &lt;code&gt;vars()&lt;/code&gt; function returns the object’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;p&gt;While this tutorial provides detailed insights into using &lt;code&gt;.__dict__&lt;/code&gt; effectively, having a solid understanding of Python &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionaries&lt;/a&gt; and how to use them in your code will help you get the most out of it.&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-dict-attribute-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-dict-attribute-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code &lt;/a&gt; you’ll use to learn about using Python’s &lt;code&gt;.__dict__&lt;/code&gt; to work with attributes.&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.6eec2e95bede.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 “Using Python&#x27;s .__dict__ to Work With Attributes” 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-dict-attribute/&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;Using Python&#x27;s .__dict__ to Work With Attributes&quot; src=&quot;https://files.realpython.com/media/Using-Pythons-.__dict__-to-Inspect-Object-Attributes_Watermarked.e648f20c0563.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Using-Pythons-.__dict__-to-Inspect-Object-Attributes_Watermarked.e648f20c0563.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Using-Pythons-.__dict__-to-Inspect-Object-Attributes_Watermarked.e648f20c0563.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Using-Pythons-.__dict__-to-Inspect-Object-Attributes_Watermarked.e648f20c0563.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Using-Pythons-.__dict__-to-Inspect-Object-Attributes_Watermarked.e648f20c0563.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.6eec2e95bede.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-dict-attribute/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Using Python&#x27;s .__dict__ to Work With Attributes&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 Python&#x27;s .__dict__ attribute and its usage in classes, instances, and functions. Acting as a namespace, this attribute maps attribute names to their corresponding values and serves as a versatile tool for metaprogramming and debugging.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-the-__dict__-attribute-in-python&quot;&gt;Getting to Know the &lt;code&gt;.__dict__&lt;/code&gt; Attribute in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-the-__dict__-attribute-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python supports the &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming (OOP)&lt;/a&gt; paradigm through &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt; that &lt;span data-invalid-ref=&quot;glossary/encapsulation&quot;&gt;encapsulate&lt;/span&gt; data (attributes) and behaviors (methods) in a single entity. Under the hood, Python takes advantage of dictionaries to handle these attributes and methods.&lt;/p&gt;
&lt;p&gt;Why dictionaries? Because they’re implemented as hash tables, which map keys to values, making lookup operations fast and efficient.&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 using Python dictionaries, check out the following resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;Dictionaries in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/iterate-through-dictionary-python/&quot;&gt;How to Iterate Through a Dictionary in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/sort-python-dictionary/&quot;&gt;Sorting a Python Dictionary: Values, Keys, and More&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-dictionary-comprehension/&quot;&gt;Python Dictionary Comprehensions: How and When to Use Them&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;Generally, Python uses a special dictionary called &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html#object.__dict__&quot;&gt;&lt;code&gt;.__dict__&lt;/code&gt;&lt;/a&gt; to maintain references to writable attributes and methods in a Python class or instance. In practice, the &lt;code&gt;.__dict__&lt;/code&gt; attribute is a &lt;a href=&quot;https://realpython.com/python-namespaces-scope/&quot;&gt;namespace&lt;/a&gt; that maps attribute names to values and method names to method objects.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;.__dict__&lt;/code&gt; attribute is fundamental to Python’s &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html&quot;&gt;data model&lt;/a&gt;. The interpreter recognizes and uses it internally to process classes and objects. It enables dynamic attribute access, addition, removal, and manipulation. You’ll learn how to do these operations in a moment. But first, you’ll look at the differences between the class &lt;code&gt;.__dict__&lt;/code&gt; and the instance &lt;code&gt;.__dict__&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;the-__dict__-class-attribute&quot;&gt;The &lt;code&gt;.__dict__&lt;/code&gt; Class Attribute&lt;a class=&quot;headerlink&quot; href=&quot;#the-__dict__-class-attribute&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To start learning about &lt;code&gt;.__dict__&lt;/code&gt; in a Python class, you’ll use the following demo class, which has attributes and methods:&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;demo.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;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;DemoClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;class_attr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;This is a class attribute&quot;&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;fm&quot;&gt;__init__&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;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_attr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;This is an instance attribute&quot;&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;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;This is a method&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.6eec2e95bede.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.6eec2e95bede.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 class, you have a class attribute, two methods, and an &lt;a href=&quot;https://realpython.com/python-classes/#instance-attributes&quot;&gt;instance attribute&lt;/a&gt;. Now, start a Python &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;REPL&lt;/a&gt; session and run the following code:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;demo&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DemoClass&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DemoClass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;vm&quot;&gt;__dict__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__module__&#x27;: &#x27;demo&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__firstlineno__&#x27;: 1,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;class_attr&#x27;: &#x27;This is a class attribute&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__init__&#x27;: &amp;lt;function DemoClass.__init__ at 0x102bcd120&amp;gt;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;method&#x27;: &amp;lt;function DemoClass.method at 0x102bcd260&amp;gt;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__static_attributes__&#x27;: (&#x27;instance_attr&#x27;,),&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__dict__&#x27;: &amp;lt;attribute &#x27;__dict__&#x27; of &#x27;DemoClass&#x27; objects&amp;gt;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__weakref__&#x27;: &amp;lt;attribute &#x27;__weakref__&#x27; of &#x27;DemoClass&#x27; objects&amp;gt;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__doc__&#x27;: None&lt;/span&gt;
&lt;span class=&quot;go&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.6eec2e95bede.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.6eec2e95bede.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The call to &lt;code&gt;print()&lt;/code&gt; displays a dictionary that maps names to objects. First, you have the &lt;code&gt;&#x27;__module__&#x27;&lt;/code&gt; key, which maps to a special attribute that specifies where the class is defined. In this case, the class lives in the &lt;code&gt;demo&lt;/code&gt; module. Then, you have the &lt;code&gt;&#x27;__firstlineno__&#x27;&lt;/code&gt; key, which holds the line number of the first line of the class definition, including decorators. Next, you have the &lt;code&gt;&#x27;class_attr&#x27;&lt;/code&gt; key and its corresponding value.&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; When you access the &lt;code&gt;.__dict__&lt;/code&gt; attribute on a class, you get a &lt;code&gt;mappingproxy&lt;/code&gt; object. This type of object creates a read-only &lt;a href=&quot;https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects&quot;&gt;view&lt;/a&gt; of a dictionary.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;&#x27;__init__&#x27;&lt;/code&gt; and &lt;code&gt;&#x27;method&#x27;&lt;/code&gt; keys map to the corresponding method objects &lt;a href=&quot;https://realpython.com/python-class-constructor/#object-initialization-with-__init__&quot;&gt;&lt;code&gt;.__init__()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;.method()&lt;/code&gt;. Next, you have a key called &lt;code&gt;&#x27;__dict__&#x27;&lt;/code&gt; that maps to the attribute &lt;code&gt;.__dict__&lt;/code&gt; of &lt;code&gt;DemoClass&lt;/code&gt; objects. You’ll explore this attribute more in a moment.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;&#x27;__static_attributes__&#x27;&lt;/code&gt; key is a tuple containing the names of the attributes that you assign through &lt;code&gt;self.attribute = value&lt;/code&gt; from any method in the class body.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;&#x27;__weakref__&#x27;&lt;/code&gt; key represents a special attribute that enables you to reference objects without preventing them from being &lt;a href=&quot;/ref/glossary/garbage-collection/&quot; class=&quot;ref-link&quot;&gt;garbage collected&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Finally, you have the &lt;code&gt;&#x27;__doc__&#x27;&lt;/code&gt; key, which maps to the class’s docstring. If the class doesn’t have a docstring, it defaults to &lt;a href=&quot;https://realpython.com/null-in-python/&quot;&gt;&lt;code&gt;None&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Did you notice that the &lt;code&gt;.instance_attr&lt;/code&gt; name doesn’t have a key in the class &lt;code&gt;.__dict__&lt;/code&gt; attribute? You’ll find out where it’s hidden in the following section.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-dict-attribute/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-dict-attribute/ »&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>Checking for Membership Using Python&#x27;s &quot;in&quot; and &quot;not in&quot; Operators</title>
      <id>https://realpython.com/courses/checking-membership-in-not-in-operators/</id>
      <link href="https://realpython.com/courses/checking-membership-in-not-in-operators/"/>
      <updated>2025-04-08T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to check if a given value is present or absent in a collection of values using Python&#x27;s in and not in operators. This type of check is known as a membership test in Python.</summary>
      <content type="html">
        &lt;p&gt;Python&amp;rsquo;s &lt;code&gt;in&lt;/code&gt; and &lt;code&gt;not in&lt;/code&gt; operators allow you to quickly check if a given value is or isn&amp;rsquo;t part of a collection of values. This type of check is generally known as a &lt;strong&gt;membership test&lt;/strong&gt; in Python. Therefore, these operators are known as &lt;strong&gt;membership operators&lt;/strong&gt;.&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;The &lt;strong&gt;&lt;code&gt;in&lt;/code&gt; operator&lt;/strong&gt; in Python is a &lt;strong&gt;membership operator&lt;/strong&gt; used to check if a value is part of a collection.&lt;/li&gt;
&lt;li&gt;You can write &lt;strong&gt;&lt;code&gt;not in&lt;/code&gt;&lt;/strong&gt; in Python to check if a value is &lt;strong&gt;absent from a collection&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Python&amp;rsquo;s membership operators work with &lt;strong&gt;several data types&lt;/strong&gt; like lists, tuples, ranges, and dictionaries.&lt;/li&gt;
&lt;li&gt;You can use &lt;strong&gt;&lt;code&gt;operator.contains()&lt;/code&gt;&lt;/strong&gt; as a function equivalent to the &lt;code&gt;in&lt;/code&gt; operator for membership testing.&lt;/li&gt;
&lt;li&gt;You can support &lt;code&gt;in&lt;/code&gt; and &lt;code&gt;not in&lt;/code&gt; in &lt;strong&gt;custom classes&lt;/strong&gt; by implementing methods like &lt;code&gt;.__contains__()&lt;/code&gt;, &lt;code&gt;.__iter__()&lt;/code&gt;, or &lt;code&gt;.__getitem__()&lt;/code&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>Python News Roundup: April 2025</title>
      <id>https://realpython.com/python-news-april-2025/</id>
      <link href="https://realpython.com/python-news-april-2025/"/>
      <updated>2025-04-07T14:00:00+00:00</updated>
      <summary>Recent milestones in the Python community include Python 3.14&#x27;s sixth alpha release and the acceptance of PEP 758. PyCon US has set new records for travel grants, and Thomas Wouters receives recognition for his long-standing contributions. Popular libraries also see significant updates.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Last month brought significant progress toward Python 3.14, exciting news from PyCon US, notable community awards, and important updates to several popular Python libraries.&lt;/p&gt;
&lt;p&gt;In this news roundup, you’ll catch up on the latest Python 3.14.0a6 developments, discover which PEP has been accepted, celebrate record-breaking community support for PyCon travel grants, and explore recent updates to popular libraries. Let’s dive in!&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 update, or post.&lt;/p&gt;&lt;/div&gt;

&lt;h2 id=&quot;python-3140a6-released-on-pi-day&quot;&gt;Python 3.14.0a6 Released on Pi Day&lt;a class=&quot;headerlink&quot; href=&quot;#python-3140a6-released-on-pi-day&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The Python development team has rolled out the &lt;a href=&quot;https://blog.python.org/2025/03/python-3140-alpha-6-is-out.html&quot;&gt;sixth alpha version&lt;/a&gt; of Python 3.14, marking the penultimate release in the planned alpha series. The date of this particular preview release coincided with &lt;a href=&quot;https://en.wikipedia.org/wiki/Pi_Day&quot;&gt;Pi Day&lt;/a&gt;, which is celebrated annually on March 14 (3/14) in the honor of the mathematical constant π, traditionally marked by eating pies.&lt;/p&gt;
&lt;p&gt;As always, the changes and improvements planned for the final Python 3.14 release, which is &lt;a href=&quot;https://peps.python.org/pep-0745/&quot;&gt;slated for October&lt;/a&gt; later this year, are outlined in the &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/changelog.html#python-3-14-0-alpha-6&quot;&gt;changelog&lt;/a&gt; and the &lt;a href=&quot;https://docs.python.org/3.14/&quot;&gt;online documentation&lt;/a&gt;. The major new features include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0649/&quot;&gt;PEP 649&lt;/a&gt;: &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#pep-649-deferred-evaluation-of-annotations&quot;&gt;Deferred Evaluation of Annotations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0741/&quot;&gt;PEP 741&lt;/a&gt;: Python Configuration C API&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0761/&quot;&gt;PEP 761&lt;/a&gt;: Deprecating PGP Signatures for CPython Artifacts&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#improved-error-messages&quot;&gt;Improved Error Messages&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-tail-call&quot;&gt;A New Type of Interpreter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#uuid&quot;&gt;Support for UUID Versions 6, 7, and 8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Python &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#removed&quot;&gt;Removals&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#deprecated&quot;&gt;Deprecations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;C API &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-c-api-removed&quot;&gt;Removals&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-c-api-deprecated&quot;&gt;Deprecations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Compared to the previous alpha release last month, Python 3.14.0a6 brings a broad mix of bug fixes, performance improvements, new features, and continued enhancements for tests and documentation. Overall, this release packs &lt;a href=&quot;https://github.com/python/cpython/compare/v3.14.0a5...v3.14.0a6&quot;&gt;nearly five hundred commits&lt;/a&gt;, most of which address specific pull requests and issues.&lt;/p&gt;
&lt;p&gt;Remember that alpha releases aren’t meant to be used in production! That said, if you’d like to get your hands dirty and give this early preview a try, then you have several choices when it comes to &lt;a href=&quot;https://realpython.com/python-pre-release/&quot;&gt;installing preview releases&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you’re a &lt;strong&gt;macOS&lt;/strong&gt; or &lt;strong&gt;Windows&lt;/strong&gt; user, then you can download the Python 3.14.0a6 installer straight from the &lt;a href=&quot;https://www.python.org/downloads/release/python-3140a6/&quot;&gt;official release page&lt;/a&gt;. To run Python without installation, which might be preferable in corporate environments, you can also download a slimmed-down, embeddable package that’s been precompiled for Windows. In such a case, you simply unpack the archive and double-click the Python executable.&lt;/p&gt;
&lt;p&gt;If you’re on &lt;strong&gt;Linux&lt;/strong&gt;, then you may find it quicker to install the latest alpha release through &lt;a href=&quot;https://realpython.com/intro-to-pyenv/&quot;&gt;&lt;code&gt;pyenv&lt;/code&gt;&lt;/a&gt;, which helps manage multiple Python versions alongside each other:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;pyenv&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;update
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;pyenv&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;.14.0a6
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;pyenv&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;shell&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;.14.0a6
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--version
&lt;span class=&quot;go&quot;&gt;Python 3.14.0a6&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.6eec2e95bede.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.6eec2e95bede.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;Don’t forget to update &lt;code&gt;pyenv&lt;/code&gt; itself first to fetch the list of available versions. Next, install Python 3.14.0a6 and set it as the default version for your current shell session. That way, when you enter &lt;code&gt;python&lt;/code&gt;, you’ll be running the sixth alpha release until you decide to close the terminal window.&lt;/p&gt;
&lt;p&gt;Alternatively, you can use &lt;a href=&quot;https://realpython.com/python-versions-docker/&quot;&gt;Docker&lt;/a&gt; to pull the corresponding image and run a container with Python 3.14.0a6 by using the following commands:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;docker&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;run&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-it&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--rm&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;python:3.14.0a6
&lt;span class=&quot;go&quot;&gt;Python 3.14.0a6 (main, Mar 18 2025, 03:31:04) [GCC 12.2.0] on linux&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;gt;&amp;gt;&amp;gt; exit&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;docker&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;run&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-it&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--rm&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-v&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pwd&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;:/app&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;python:3.14.0a6&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/app/hello.py
&lt;span class=&quot;go&quot;&gt;Hello, World!&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.6eec2e95bede.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.6eec2e95bede.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The first command drops you into the &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python REPL&lt;/a&gt;, where you can interactively execute Python code and test snippets in real time. The other command mounts your current directory into the container and runs a Python script named &lt;code&gt;hello.py&lt;/code&gt; from that directory. This lets you &lt;a href=&quot;https://realpython.com/run-python-scripts/&quot;&gt;run local Python scripts&lt;/a&gt; within the containerized environment.&lt;/p&gt;
&lt;p&gt;Finally, if none of the methods above work for you, then you can build the release from source code. You can get the Python source code from the downloads page mentioned earlier or by cloning the &lt;a href=&quot;https://github.com/python/cpython&quot;&gt;&lt;code&gt;python/cpython&lt;/code&gt;&lt;/a&gt; repository from GitHub:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;git&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;clone&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;git@github.com:python/cpython.git&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--branch&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;v3.14.0a6&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--single-branch
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;cpython/
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;./configure&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--enable-optimizations
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;make&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-j&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;nproc&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;./python
&lt;span class=&quot;go&quot;&gt;Python 3.14.0a6 (tags/v3.14.0a6:77b2c933ca, Mar 26 2025, 17:43:06) [GCC 13.3.0] on linux&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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.6eec2e95bede.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;--single-branch&lt;/code&gt; option tells your &lt;a href=&quot;https://realpython.com/python-git-github-intro/&quot;&gt;Git&lt;/a&gt; client to clone only the specified tag (&lt;a href=&quot;https://github.com/python/cpython/releases/tag/v3.14.0a6&quot;&gt;&lt;code&gt;v3.14.0a6&lt;/code&gt;&lt;/a&gt;) and its history without downloading all the other branches from the remote repository. The &lt;code&gt;make -j $(nproc)&lt;/code&gt; command compiles Python using all available CPU cores, which speeds up the build process significantly. Once the build is complete, you can run the newly compiled Python interpreter with &lt;code&gt;./python&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To continue with the π theme, Python 3.14 includes a new &lt;a href=&quot;https://realpython.com/courses/finding-python-easter-eggs/&quot;&gt;Easter egg&lt;/a&gt;. Do you think you can find it? Let us know in the comments below!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-april-2025/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-april-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 #245: GUIs &amp; TUIs: Choosing a User Interface for Your Python Project</title>
      <id>https://realpython.com/podcasts/rpp/245/</id>
      <link href="https://realpython.com/podcasts/rpp/245/"/>
      <updated>2025-04-04T12:00:00+00:00</updated>
      <summary>What are the current Python graphical user interface libraries? Should you build everything in the terminal and create a text-based user interface instead? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the current Python graphical user interface libraries? Should you build everything in the terminal and create a text-based user interface instead? 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>How to Strip Characters From a Python String</title>
      <id>https://realpython.com/python-strip/</id>
      <link href="https://realpython.com/python-strip/"/>
      <updated>2025-04-02T14:00:00+00:00</updated>
      <summary>Use Python&#x27;s .strip() method to remove unwanted whitespace or specific characters. Learn about common pitfalls, real-world use cases, and compare .strip() with similar methods like .lstrip() and .removesuffix().</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;By default, Python’s &lt;code&gt;.strip()&lt;/code&gt; method removes whitespace characters from both ends of a string. To remove different characters, you can pass a string as an argument that specifies a set of characters to remove. The &lt;code&gt;.strip()&lt;/code&gt; method is useful for tasks like cleaning user input, standardizing filenames, and preparing data for storage.&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;The &lt;code&gt;.strip()&lt;/code&gt; method &lt;strong&gt;removes leading and trailing whitespace&lt;/strong&gt; but doesn’t remove whitespace from the middle of a string.&lt;/li&gt;
&lt;li&gt;You can use &lt;code&gt;.strip()&lt;/code&gt; to remove &lt;strong&gt;specified characters&lt;/strong&gt; from both ends of the string by providing these characters as an &lt;strong&gt;argument&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;With the related methods &lt;strong&gt;&lt;code&gt;.lstrip()&lt;/code&gt; and &lt;code&gt;.rstrip()&lt;/code&gt;&lt;/strong&gt;, you can remove characters from &lt;strong&gt;one side&lt;/strong&gt; of the string only.&lt;/li&gt;
&lt;li&gt;All three methods, &lt;code&gt;.strip()&lt;/code&gt;, &lt;code&gt;.lstrip()&lt;/code&gt;, and &lt;code&gt;.rstrip()&lt;/code&gt;, &lt;strong&gt;remove character sets, not sequences&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can use &lt;strong&gt;&lt;code&gt;.removeprefix()&lt;/code&gt; and &lt;code&gt;.removesuffix()&lt;/code&gt;&lt;/strong&gt; to &lt;strong&gt;strip character sequences&lt;/strong&gt; from the start or end of a string.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this tutorial, you’ll explore the nuances of &lt;code&gt;.strip()&lt;/code&gt; and other Python string methods that allow you to strip parts of a string. You’ll also learn about common pitfalls and read about practical real-world scenarios, such as cleaning datasets and standardizing user input.
To get the most out of this tutorial, you should have a basic understanding of &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;Python strings and character data&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-strip-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-strip-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 strip characters from a Python string.&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.6eec2e95bede.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 Strip Characters From a Python String” 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-strip/&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 Strip Characters From a Python String?&quot; src=&quot;https://files.realpython.com/media/How-to-Strip-Characters-from-a-Python-String_Watermarked.00bc2bde8568.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-Strip-Characters-from-a-Python-String_Watermarked.00bc2bde8568.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Strip-Characters-from-a-Python-String_Watermarked.00bc2bde8568.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Strip-Characters-from-a-Python-String_Watermarked.00bc2bde8568.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Strip-Characters-from-a-Python-String_Watermarked.00bc2bde8568.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.6eec2e95bede.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-strip/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;How to Strip Characters From a Python String&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 Python&#x27;s .strip(), .lstrip(), and .rstrip() methods, as well as .removeprefix() and .removesuffix(). These methods are useful for tasks like cleaning user input, standardizing filenames, and preparing data for storage.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;how-to-use-pythons-strip-method-to-remove-whitespace-from-strings&quot;&gt;How to Use Python’s &lt;code&gt;.strip()&lt;/code&gt; Method to Remove Whitespace From Strings&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-use-pythons-strip-method-to-remove-whitespace-from-strings&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python’s &lt;code&gt;.strip()&lt;/code&gt; method provides a quick and reliable way to remove unwanted spaces, tabs, and newline characters from both the beginning and end of a &lt;a href=&quot;/ref/builtin-types/str/&quot; class=&quot;ref-link&quot;&gt;string&lt;/a&gt;. This makes it useful for tasks like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Validating user input&lt;/strong&gt;, such as trimming spaces from email addresses, usernames, and other user-provided data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cleaning messy text&lt;/strong&gt; gathered through &lt;a href=&quot;https://realpython.com/python-web-scraping-practical-introduction/&quot;&gt;web scraping&lt;/a&gt; or other sources.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Preparing data for storage&lt;/strong&gt; to ensure uniformity before saving text to a database.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Standardizing logs&lt;/strong&gt; by removing unwanted spaces.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you don’t provide any &lt;a href=&quot;/ref/glossary/argument/&quot; class=&quot;ref-link&quot;&gt;arguments&lt;/a&gt; to the method, then &lt;code&gt;.strip()&lt;/code&gt; removes all leading and trailing whitespace characters, leaving any whitespace within the string untouched:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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;original_string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;   Hello, World!   &quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;original_string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;Hello, World!&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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.6eec2e95bede.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When you call &lt;code&gt;.strip()&lt;/code&gt; on a string &lt;a href=&quot;/ref/glossary/object/&quot; class=&quot;ref-link&quot;&gt;object&lt;/a&gt;, Python removes the leading and trailing spaces while keeping the spaces between words unchanged, like in &lt;code&gt;&quot;Hello,&quot;&lt;/code&gt; and &lt;code&gt;&quot;World!&quot;&lt;/code&gt;. This can be a great way to clean up text data without affecting the content itself.&lt;/p&gt;
&lt;p&gt;However, whitespace isn’t just about spaces—it also includes common characters such as newlines (&lt;code&gt;\n&lt;/code&gt;) and tabs (&lt;code&gt;\t&lt;/code&gt;). These often appear when you’re dealing with multi-line strings or reading data from files. The default invocation of &lt;code&gt;.strip()&lt;/code&gt; effectively removes them as well:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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;text&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;  This is a messy multi-line string.&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\t&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;This is a messy multi-line string.&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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.6eec2e95bede.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;Here, &lt;code&gt;.strip()&lt;/code&gt; removes all leading and trailing whitespace characters, including newlines and tabs, leaving only the text content. After having cleaned your strings using &lt;code&gt;.strip()&lt;/code&gt;, they’re in better condition for displaying or further processing the text. This can be especially useful when you’re dealing with structured data, such as logs or CSV files, where you need to process many strings in a row.&lt;/p&gt;
&lt;p&gt;At this point, you’ve learned how &lt;code&gt;.strip()&lt;/code&gt; handles whitespace removal. But what if you need to strip specific characters, not just whitespace? In the next section, you’ll see how you can use this method to remove any unwanted characters from the start and end of a string.&lt;/p&gt;
&lt;h2 id=&quot;remove-specific-characters-with-strip&quot;&gt;Remove Specific Characters With &lt;code&gt;.strip()&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#remove-specific-characters-with-strip&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Sometimes, you need to remove specific characters other than whitespace. For example, when your text is delimited by unwanted symbols, or when you have to handle text that’s plagued by formatting issues. You can use &lt;code&gt;.strip()&lt;/code&gt; to remove specific characters by passing these characters as an argument to the method:&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;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;cleaned_string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;original_string&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chars&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;None&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.6eec2e95bede.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.6eec2e95bede.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;Here, &lt;code&gt;chars&lt;/code&gt; is a string argument that you can pass to &lt;code&gt;.strip()&lt;/code&gt;. If you don’t pass it, then it defaults to &lt;code&gt;None&lt;/code&gt;, which means the method will remove whitespace characters.&lt;/p&gt;
&lt;p&gt;Instead, you can pass a string value that contains all the characters needing removal from both ends of the target string. Note that &lt;code&gt;.strip()&lt;/code&gt; doesn’t treat the argument as a prefix or suffix, but rather as a set of individual characters to strip. In the rest of this section, you’ll explore use cases of passing specific characters to &lt;code&gt;.strip()&lt;/code&gt; for cleaning the beginning and end of a string.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;.strip()&lt;/code&gt; method is useful when you want to remove punctuation marks, specific symbols, or other unwanted characters. For example, in &lt;a href=&quot;https://realpython.com/python-nltk-sentiment-analysis/&quot;&gt;sentiment analysis&lt;/a&gt; tasks, you may need to remove question marks or exclamation marks from text data:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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;review&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;!!This product is incredible!!!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;review&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&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;go&quot;&gt;&#x27;This product is incredible&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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.6eec2e95bede.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;Since you pass &lt;code&gt;&quot;!&quot;&lt;/code&gt; as an argument, &lt;code&gt;.strip()&lt;/code&gt; removes all exclamation marks from both ends of the string while leaving the text content intact. Keep in mind that &lt;code&gt;.strip()&lt;/code&gt; removes all occurrences of the specified characters at once, not just the first one it encounters.&lt;/p&gt;
&lt;p&gt;You can also use &lt;code&gt;.strip()&lt;/code&gt; to remove multiple specified characters from both ends of a string. For example, some of the product reviews you’re dealing with may be in Spanish and use a combination of exclamation marks and inverted exclamation marks:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-strip/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-strip/ »&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>Building a Code Image Generator With Python</title>
      <id>https://realpython.com/courses/code-image-generator/</id>
      <link href="https://realpython.com/courses/code-image-generator/"/>
      <updated>2025-04-01T14:00:00+00:00</updated>
      <summary>In this step-by-step video course, you&#x27;ll build a code image generator that creates nice-looking images of your code snippets to share on social media. Your code image generator will be powered by the Flask web framework and include exciting packages like Pygments and Playwright.</summary>
      <content type="html">
        &lt;p&gt;If you&amp;rsquo;re active on social media, then you know that images and videos are popular forms of content. As a programmer, you mainly work with text, so sharing the content that you create on a daily basis may not seem intuitive. That&amp;rsquo;s where a code image generator comes in handy!&lt;/p&gt;
&lt;p&gt;A code image generator allows you to turn your code snippets into visually appealing images, so you can share your work without worrying about formatting issues, syntax highlighting inconsistencies, or character count limits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this step-by-step video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set up and run a &lt;strong&gt;Flask project&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Connect and style &lt;strong&gt;Jinja templates&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Playwright&lt;/strong&gt; to create images&lt;/li&gt;
&lt;li&gt;Beautify code with &lt;strong&gt;Pygments&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Leverage &lt;strong&gt;sessions&lt;/strong&gt; to save browser states&lt;/li&gt;
&lt;li&gt;Enhance the user experience with &lt;strong&gt;JavaScript&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>Python&#x27;s Bytearray: A Mutable Sequence of Bytes</title>
      <id>https://realpython.com/python-bytearray/</id>
      <link href="https://realpython.com/python-bytearray/"/>
      <updated>2025-03-31T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about Python&#x27;s bytearray, a mutable sequence of bytes for efficient binary data manipulation. You&#x27;ll explore how it differs from bytes, how to create and modify bytearray objects, and when to use them in tasks like processing binary files and network protocols.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;bytearray&lt;/code&gt; is a mutable sequence of bytes that allows you to manipulate binary data efficiently. Unlike immutable &lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;bytearray&lt;/code&gt; can be modified in place, making it suitable for tasks requiring frequent updates to byte sequences.&lt;/p&gt;
&lt;p&gt;You can create a &lt;code&gt;bytearray&lt;/code&gt; using the &lt;code&gt;bytearray()&lt;/code&gt; constructor with various arguments or from a string of hexadecimal digits using &lt;code&gt;.fromhex()&lt;/code&gt;. This tutorial explores creating, modifying, and using &lt;code&gt;bytearray&lt;/code&gt; objects in Python.&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;A &lt;code&gt;bytearray&lt;/code&gt; in Python&lt;/strong&gt; is a mutable sequence of bytes that allows in-place modifications, unlike the immutable &lt;code&gt;bytes&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You create a &lt;code&gt;bytearray&lt;/code&gt;&lt;/strong&gt; by using the &lt;code&gt;bytearray()&lt;/code&gt; constructor with a non-negative integer, iterable of integers, bytes-like object, or a string with specified encoding.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;You can modify a &lt;code&gt;bytearray&lt;/code&gt;&lt;/strong&gt; in Python by appending, slicing, or changing individual bytes, thanks to its mutable nature.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Common uses for &lt;code&gt;bytearray&lt;/code&gt;&lt;/strong&gt; include processing large binary files, working with network protocols, and tasks needing frequent updates to byte sequences.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll dive deeper into each aspect of &lt;code&gt;bytearray&lt;/code&gt;, exploring its creation, manipulation, and practical applications in Python programming.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-bytearray-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-bytearray-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to learn about Python’s bytearray data type.&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.6eec2e95bede.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 Bytearray” 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-bytearray/&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;Python&#x27;s Bytearray: A Mutable Sequence of Bytes&quot; src=&quot;https://files.realpython.com/media/Pythons-Bytearray_Watermarked.736fb67a3a9a.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Pythons-Bytearray_Watermarked.736fb67a3a9a.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Pythons-Bytearray_Watermarked.736fb67a3a9a.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Pythons-Bytearray_Watermarked.736fb67a3a9a.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Pythons-Bytearray_Watermarked.736fb67a3a9a.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.6eec2e95bede.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-bytearray/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python&#x27;s Bytearray&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 Python&#x27;s bytearray data type. By working through this quiz, you&#x27;ll revisit the key concepts and uses of bytearray in Python.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;understanding-pythons-bytearray-type&quot;&gt;Understanding Python’s &lt;code&gt;bytearray&lt;/code&gt; Type&lt;a class=&quot;headerlink&quot; href=&quot;#understanding-pythons-bytearray-type&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Although Python remains a high-level programming language, it exposes a few specialized data types that let you manipulate binary data directly should you ever need to. These data types can be useful for tasks such as processing custom binary file formats, or working with low-level network protocols requiring precise control over the data.&lt;/p&gt;
&lt;p&gt;The three closely related &lt;a href=&quot;https://docs.python.org/3/library/stdtypes.html#binaryseq&quot;&gt;binary sequence types&lt;/a&gt; built into the language are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;bytes&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bytearray&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;memoryview&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;While they’re all &lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;Python sequences&lt;/a&gt; optimized for performance when dealing with binary data, they each have slightly different strengths and use cases.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You’ll take a deep dive into Python’s &lt;code&gt;bytearray&lt;/code&gt; in this tutorial. But, if you’d like to learn more about the companion &lt;code&gt;bytes&lt;/code&gt; data type, then check out &lt;a href=&quot;https://realpython.com/python-bytes/&quot;&gt;Bytes Objects: Handling Binary Data in Python&lt;/a&gt;, which also covers binary data fundamentals.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As both names suggest, &lt;a href=&quot;/ref/builtin-types/bytes/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;bytes&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;/ref/builtin-types/bytearray/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;bytearray&lt;/code&gt;&lt;/a&gt; are sequences of individual &lt;em&gt;byte&lt;/em&gt; values, letting you process binary data at the &lt;strong&gt;byte level&lt;/strong&gt;. For example, you may use them to work with plain text data, which typically represents characters as unique byte values, depending on the given &lt;a href=&quot;https://realpython.com/python-encodings-guide/&quot;&gt;character encoding&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Python natively interprets bytes as 8-bit &lt;a href=&quot;https://realpython.com/python-bitwise-operators/#unsigned-integers&quot;&gt;unsigned integers&lt;/a&gt;, each representing one of 256 possible values (2&lt;sup&gt;8&lt;/sup&gt;) between 0 and 255. But sometimes, you may need to interpret the same bit pattern as a &lt;a href=&quot;https://realpython.com/python-bitwise-operators/#signed-integers&quot;&gt;signed integer&lt;/a&gt;, for example, when handling digital audio samples that encode a sound wave’s amplitude levels. See the &lt;a href=&quot;https://realpython.com/python-bytes/#signedness-and-the-sign-bit&quot;&gt;section on signedness&lt;/a&gt; in the Python &lt;code&gt;bytes&lt;/code&gt; tutorial for more details.&lt;/p&gt;
&lt;p&gt;The choice between &lt;code&gt;bytes&lt;/code&gt; and &lt;code&gt;bytearray&lt;/code&gt; boils down to whether you want read-only access to the underlying bytes or not. Instances of the &lt;code&gt;bytes&lt;/code&gt; data type are &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/&quot;&gt;immutable&lt;/a&gt;, meaning each one has a fixed value that you can’t change once the object is created. In contrast, &lt;code&gt;bytearray&lt;/code&gt; objects are &lt;strong&gt;mutable sequences&lt;/strong&gt;, allowing you to modify their contents after creation.&lt;/p&gt;
&lt;p&gt;While it may seem counterintuitive at first—since many newcomers to Python expect objects to be directly modifiable—immutable objects have several benefits over their mutable counterparts. That’s why types like strings, tuples, and others require reassignment in Python.&lt;/p&gt;
&lt;p&gt;The advantages of immutable data types include better memory efficiency due to the ability to &lt;a href=&quot;https://realpython.com/lru-cache-python/&quot;&gt;cache&lt;/a&gt; or reuse objects without unnecessary copying. In Python, immutable objects are inherently &lt;a href=&quot;/ref/glossary/hashable/&quot; class=&quot;ref-link&quot;&gt;hashable&lt;/a&gt;, so they can become &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt; keys or &lt;a href=&quot;https://realpython.com/python-sets/&quot;&gt;set&lt;/a&gt; elements. Additionally, relying on immutable objects gives you extra security, data integrity, and &lt;a href=&quot;https://realpython.com/python-thread-lock/&quot;&gt;thread safety&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;That said, if you need a binary sequence that allows for modification, then &lt;code&gt;bytearray&lt;/code&gt; is the way to go. Use it when you frequently perform &lt;a href=&quot;https://en.wikipedia.org/wiki/In-place_algorithm&quot;&gt;in-place&lt;/a&gt; byte operations that involve changing the contents of the sequence, such as appending, inserting, extending, or modifying individual bytes. A scenario where &lt;code&gt;bytearray&lt;/code&gt; can be particularly useful includes processing large binary files in chunks or incrementally reading messages from a network buffer.&lt;/p&gt;
&lt;p&gt;The third binary sequence type in Python mentioned earlier, &lt;a href=&quot;/ref/builtin-functions/memoryview/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;memoryview&lt;/code&gt;&lt;/a&gt;, provides a zero-overhead view into the memory of certain objects. Unlike &lt;code&gt;bytes&lt;/code&gt; and &lt;code&gt;bytearray&lt;/code&gt;, whose mutability status is fixed, a &lt;code&gt;memoryview&lt;/code&gt; can be either mutable or immutable depending on the target object it references. Just like &lt;code&gt;bytes&lt;/code&gt; and &lt;code&gt;bytearray&lt;/code&gt;, a &lt;code&gt;memoryview&lt;/code&gt; may represent a series of single bytes, but at the same time, it can represent a sequence of &lt;a href=&quot;https://en.wikipedia.org/wiki/Word_(computer_architecture)&quot;&gt;multi-byte words&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now that you have a basic understanding of Python’s binary sequence types and where &lt;code&gt;bytearray&lt;/code&gt; fits into them, you can explore ways to create and work with &lt;code&gt;bytearray&lt;/code&gt; objects in Python.&lt;/p&gt;
&lt;h2 id=&quot;creating-bytearray-objects-in-python&quot;&gt;Creating &lt;code&gt;bytearray&lt;/code&gt; Objects in Python&lt;a class=&quot;headerlink&quot; href=&quot;#creating-bytearray-objects-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Unlike the immutable &lt;code&gt;bytes&lt;/code&gt; data type, whose &lt;a href=&quot;https://realpython.com/python-bytes/#the-bytes-literal-format&quot;&gt;literal form&lt;/a&gt; resembles a string literal prefixed with the letter &lt;code&gt;b&lt;/code&gt;—for example, &lt;code&gt;b&quot;GIF89a&quot;&lt;/code&gt;—the mutable &lt;code&gt;bytearray&lt;/code&gt; has &lt;strong&gt;no literal syntax&lt;/strong&gt; in Python. This distinction is important despite many similarities between both byte-oriented sequences, which you’ll discover in the next section.&lt;/p&gt;
&lt;p&gt;The primary way to create new &lt;code&gt;bytearray&lt;/code&gt; instances is by explicitly calling the type’s &lt;a href=&quot;https://realpython.com/python-class-constructor/&quot;&gt;class constructor&lt;/a&gt;, sometimes informally known as the &lt;code&gt;bytearray()&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-built-in-functions/&quot;&gt;built-in function&lt;/a&gt;. Alternatively, you can create a &lt;code&gt;bytearray&lt;/code&gt; from a string of hexadecimal digits. You’ll learn about both methods next.&lt;/p&gt;
&lt;h3 id=&quot;the-bytearray-constructor&quot;&gt;The &lt;code&gt;bytearray()&lt;/code&gt; Constructor&lt;a class=&quot;headerlink&quot; href=&quot;#the-bytearray-constructor&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-bytearray/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-bytearray/ »&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: Using Python&#x27;s .__dict__ to Work With Attributes</title>
      <id>https://realpython.com/quizzes/python-dict-attribute/</id>
      <link href="https://realpython.com/quizzes/python-dict-attribute/"/>
      <updated>2025-03-27T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s .__dict__ attribute and its usage in classes, instances, and functions. Acting as a namespace, this attribute maps attribute names to their corresponding values and serves as a versatile tool for metaprogramming and debugging.</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-dict-attribute/&quot;&gt;Using Python&amp;rsquo;s &lt;code&gt;.__dict__&lt;/code&gt; to Work With Attributes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how &lt;code&gt;.__dict__&lt;/code&gt; holds an object&amp;rsquo;s writable attributes, allowing for dynamic manipulation and introspection. You&amp;rsquo;ll also review how both &lt;code&gt;vars()&lt;/code&gt; and &lt;code&gt;.__dict__&lt;/code&gt; let you inspect an object&amp;rsquo;s attributes, and the common use cases of &lt;code&gt;.__dict__&lt;/code&gt; in Python applications.&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>Introducing DuckDB</title>
      <id>https://realpython.com/python-duckdb/</id>
      <link href="https://realpython.com/python-duckdb/"/>
      <updated>2025-03-26T14:00:00+00:00</updated>
      <summary>In this showcase tutorial, you&#x27;ll be introduced to a library that allows you to use a database in your code. DuckDB provides an efficient relational database that supports many features you may already be familiar with from more traditional relational database systems.</summary>
      <content type="html">
        &lt;div&gt;&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’s Python API.&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;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’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;p&gt;The tutorial will equip you with the practical knowledge necessary to get started with DuckDB, including its &lt;a href=&quot;https://en.wikipedia.org/wiki/Online_analytical_processing&quot;&gt;Online Analytical Processing (OLAP)&lt;/a&gt; features, which enable fast access to data through query optimization and buffering.&lt;/p&gt;
&lt;p&gt;Ideally, you should already have a basic understanding of &lt;a href=&quot;https://www.sqltutorial.org/sql-syntax/&quot;&gt;SQL&lt;/a&gt;, particularly how its &lt;code&gt;SELECT&lt;/code&gt; keyword can be used to read data from a relational database. However, the SQL language is very user-friendly, and the examples used here are self-explanatory.&lt;/p&gt;
&lt;p&gt;Now, it’s time for you to start learning why there’s a growing buzz surrounding &lt;a href=&quot;https://duckdb.org/&quot;&gt;DuckDB&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-duckdb-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-duckdb-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 DuckDB 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.6eec2e95bede.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 “Introducing DuckDB” 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/introducing-duckdb/&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;Introducing DuckDB&quot; src=&quot;https://files.realpython.com/media/Showcase-DuckDB_Watermarked.4ff6c6a498a1.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Showcase-DuckDB_Watermarked.4ff6c6a498a1.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Showcase-DuckDB_Watermarked.4ff6c6a498a1.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Showcase-DuckDB_Watermarked.4ff6c6a498a1.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Showcase-DuckDB_Watermarked.4ff6c6a498a1.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.6eec2e95bede.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/introducing-duckdb/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Introducing DuckDB&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;This quiz will challenge your knowledge of working with DuckDB. You won&#x27;t find all the answers in the tutorial, so you&#x27;ll need to do some extra investigation. By finding all the answers, you&#x27;re sure to learn some interesting things along the way.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-started-with-duckdb&quot;&gt;Getting Started With DuckDB&lt;a class=&quot;headerlink&quot; href=&quot;#getting-started-with-duckdb&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To use DuckDB, you first need to install it. Fortunately, DuckDB is self-contained, meaning it won’t interfere with your existing Python environment.&lt;/p&gt;
&lt;p&gt;You use &lt;code&gt;python -m pip install duckdb&lt;/code&gt; to install it from the command prompt. If you’re working in a Jupyter Notebook, the command becomes &lt;code&gt;!python -m pip install duckdb&lt;/code&gt;. The supporting downloadable code for this tutorial is also presented in a Jupyter Notebook.&lt;/p&gt;
&lt;p&gt;Once the installation is complete, you can quickly test your installation with a query:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;duckdb&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;duckdb&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;SELECT &#x27;whistling_duck&#x27; AS waterfowl, &#x27;whistle&#x27; AS call&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;┌────────────────┬─────────┐&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;│   waterfowl    │  call   │&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;│    varchar     │ varchar │&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;├────────────────┼─────────┤&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;│ whistling_duck │ whistle │&lt;/span&gt;
&lt;span class=&quot;go&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.6eec2e95bede.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.6eec2e95bede.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 test that everything works, you first import the &lt;code&gt;duckdb&lt;/code&gt; library before running a test SQL &lt;strong&gt;query&lt;/strong&gt;. In SQL, a query is a command you use to interact with the data in your database. You commonly use queries to view, add, update, and delete your data.   &lt;/p&gt;
&lt;p&gt;In this example, you write a SQL &lt;code&gt;SELECT&lt;/code&gt; statement to view some data defined by the query. By passing it to the &lt;code&gt;sql()&lt;/code&gt; function, you run the query and produce the result shown.&lt;/p&gt;
&lt;p&gt;Your query creates a table with two columns named &lt;code&gt;waterfowl&lt;/code&gt; and &lt;code&gt;call&lt;/code&gt;. These contain the data &lt;code&gt;&quot;whistling_duck&quot;&lt;/code&gt; and &lt;code&gt;&quot;whistle&quot;&lt;/code&gt;, respectively. The data types of both columns are &lt;code&gt;varchar&lt;/code&gt;, which is the data type DuckDB uses to store variable-length character strings. Running your query using &lt;code&gt;duckdb.sql()&lt;/code&gt; uses the default in-memory database. This means that the data are temporary and will disappear when you end your Python session.&lt;/p&gt;
&lt;p&gt;If you see the output shown above, your installation is working perfectly.&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; DuckDB queries are not case-sensitive. However, writing reserved SQL keywords in uppercase is standard practice. Also, a terminating semicolon (;) is optional in SQL and isn’t used in this tutorial, though you may encounter it elsewhere.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now that you know how to set things up, it’s time to dive into some of the features that make DuckDB easy to use. In the next section, you’ll create a database table using data imported from an existing file. You’ll also learn how to check that the data has been imported correctly.&lt;/p&gt;
&lt;h3 id=&quot;creating-a-database-from-a-data-source&quot;&gt;Creating a Database From a Data Source&lt;a class=&quot;headerlink&quot; href=&quot;#creating-a-database-from-a-data-source&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;While it’s possible to create database tables using SQL, it’s more common to read data from an external file, perhaps one containing data you’ve extracted from another system, and allow DuckDB to create and populate the table.&lt;/p&gt;
&lt;p&gt;DuckDB supports reading from and writing to a range of common file types such as Parquet, CSV, and JSON. In this example, you’ll use data stored in the &lt;code&gt;presidents.parquet&lt;/code&gt; &lt;a href=&quot;https://en.wikipedia.org/wiki/Apache_Parquet&quot;&gt;Parquet&lt;/a&gt; file included in your downloadable materials to create a table.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;presidents.parquet&lt;/code&gt; file contains the following six fields:&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;Heading&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sequence&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Order of presidency&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int64&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;last_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;President’s last name&lt;/td&gt;
&lt;td&gt;&lt;code&gt;varchar&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;first_name&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;President’s first name&lt;/td&gt;
&lt;td&gt;&lt;code&gt;varchar&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;term_start&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Start of presidency term&lt;/td&gt;
&lt;td&gt;&lt;code&gt;date&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;term_end&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;End of presidency term&lt;/td&gt;
&lt;td&gt;&lt;code&gt;date&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;party_id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Number representing political party&lt;/td&gt;
&lt;td&gt;&lt;code&gt;int64&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;When you import data, it gets placed into a &lt;code&gt;DuckDBPyRelation&lt;/code&gt; object. In DuckDB, a &lt;strong&gt;relation&lt;/strong&gt; stores a query definition but not its data. To see the data your relation represents, you must do so interactively by viewing it or running an SQL query against it to see specific data.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-duckdb/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-duckdb/ »&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>What Can You Do With Python?</title>
      <id>https://realpython.com/courses/what-can-you-do-with-python/</id>
      <link href="https://realpython.com/courses/what-can-you-do-with-python/"/>
      <updated>2025-03-25T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll find a set of guidelines that will help you start applying your Python skills to solve real-world problems. By the end, you&#x27;ll be able to answer the question, &quot;What can you do with Python?&quot;</summary>
      <content type="html">
        &lt;p&gt;You&amp;rsquo;ve finished a course or finally made it to the end of a &lt;a href=&quot;https://realpython.com/products/python-basics-book/&quot;&gt;book&lt;/a&gt; that teaches you the &lt;a href=&quot;https://realpython.com/learning-paths/python3-introduction/&quot;&gt;basics of programming with Python&lt;/a&gt;. You&amp;rsquo;ve learned about &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;lists, tuples&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionaries&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-while-loop/&quot;&gt;&lt;code&gt;while&lt;/code&gt;&lt;/a&gt; loops, &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;conditional statements&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented concepts&lt;/a&gt;, and more. So, what&amp;rsquo;s next? What can you do with Python nowadays?&lt;/p&gt;
&lt;p&gt;Python is a versatile programming language with many use cases in a variety of different fields. If you&amp;rsquo;ve grasped the basics of Python and are itching to build something with the language, then it&amp;rsquo;s time to figure out what your next step should be.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll see how you can use Python for:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Doing general &lt;strong&gt;software development&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Diving into &lt;strong&gt;data science and math&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Speeding up and automating your &lt;strong&gt;workflow&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Building &lt;strong&gt;embedded systems&lt;/strong&gt; and &lt;strong&gt;robots&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>Quiz: Python&#x27;s Instance, Class, and Static Methods Demystified</title>
      <id>https://realpython.com/quizzes/instance-class-and-static-methods-demystified/</id>
      <link href="https://realpython.com/quizzes/instance-class-and-static-methods-demystified/"/>
      <updated>2025-03-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of instance, class, and static methods in Python. By working through this quiz, you&#x27;ll revisit the differences between these methods and how to use them effectively in your Python code.</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/instance-class-and-static-methods-demystified/&quot;&gt;Instance, Class, and Static Methods in Python&lt;/a&gt;. By working through this quiz, you&amp;rsquo;ll revisit the differences between these methods and how to use them effectively in your Python code.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: GitHub Actions for Python</title>
      <id>https://realpython.com/quizzes/github-actions-python/</id>
      <link href="https://realpython.com/quizzes/github-actions-python/"/>
      <updated>2025-03-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of GitHub Actions for Python. By working through this quiz, you&#x27;ll revisit how to use GitHub Actions and workflows to automate linting, testing, and deployment of a Python project.</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/github-actions-python/&quot;&gt;Continuous Integration and Deployment for Python With GitHub Actions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to use GitHub Actions and workflows to automate linting, testing, and deployment of a Python project. You&amp;rsquo;ll also review how to secure your credentials and automate security and dependency updates.&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: Dictionaries in Python</title>
      <id>https://realpython.com/quizzes/dictionaries-in-python/</id>
      <link href="https://realpython.com/quizzes/dictionaries-in-python/"/>
      <updated>2025-03-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s dict data type. By working through this quiz, you&#x27;ll revisit how to create and manipulate dictionaries, how to use Python&#x27;s operators and built-in functions with them, and how they&#x27;re implemented for efficient data retrieval.</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-dicts/&quot;&gt;Dictionaries in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to create dictionaries using literals and the &lt;code&gt;dict()&lt;/code&gt; constructor, how to use Python&amp;rsquo;s operators and built-in functions to manipulate them, and how they&amp;rsquo;re implemented as a hash map for fast key lookups.&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 Set Comprehensions: How and When to Use Them</title>
      <id>https://realpython.com/quizzes/python-set-comprehension/</id>
      <link href="https://realpython.com/quizzes/python-set-comprehension/"/>
      <updated>2025-03-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python set comprehensions. Set comprehensions are a concise and quick way to create, transform, and filter sets in Python. They can significantly enhance your code&#x27;s conciseness and readability compared to using regular for loops to process your sets.</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-set-comprehension/&quot;&gt;Python Set Comprehensions: How and When to Use Them&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Set comprehensions are a concise and quick way to create, transform, and filter sets in Python.
They can significantly enhance your code&amp;rsquo;s conciseness and readability compared to using regular &lt;code&gt;for&lt;/code&gt; loops to process your sets.&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 Code Quality: Best Practices and Tools</title>
      <id>https://realpython.com/python-code-quality/</id>
      <link href="https://realpython.com/python-code-quality/"/>
      <updated>2025-03-24T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about code quality and the key factors that make Python code high-quality. You&#x27;ll explore effective strategies, powerful tools, and best practices to elevate your code to the next level.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Producing high-quality Python code involves using appropriate &lt;strong&gt;tools&lt;/strong&gt; and consistently applying &lt;strong&gt;best practices&lt;/strong&gt;. High-quality code is functional, readable, maintainable, efficient, and secure. It adheres to established standards and has excellent documentation.&lt;/p&gt;
&lt;p&gt;You can achieve these qualities by following best practices such as descriptive naming, consistent coding style, modular design, and robust error handling. To help you with all this, you can use tools such as linters, formatters, and profilers.&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;Checking the quality of Python code&lt;/strong&gt; involves using tools like linters and static type checkers to ensure adherence to coding standards and detect potential errors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Writing quality code in Python&lt;/strong&gt; requires following best practices, such as clear naming conventions, modular design, and comprehensive testing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Good Python code&lt;/strong&gt; is characterized by readability, maintainability, efficiency, and adherence to standards like PEP 8.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Making Python code look good&lt;/strong&gt; involves using formatters to ensure consistent styling and readability, aligning with established coding styles.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Making Python code readable&lt;/strong&gt; means using descriptive names for variables, functions, classes, modules, and packages.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Read on to learn more about the strategies, tools, and best practices that will help you write high-quality Python 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-code-quality-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-code-quality-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code &lt;/a&gt; that you’ll use to learn about Python code quality best practices and tools.&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.6eec2e95bede.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 Code Quality: Best Practices and Tools” 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-code-quality/&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;Python Code Quality Illustration&quot; src=&quot;https://files.realpython.com/media/code_quality_img.73eae557a204.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/code_quality_img.73eae557a204.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/code_quality_img.73eae557a204.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/code_quality_img.73eae557a204.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/code_quality_img.73eae557a204.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.6eec2e95bede.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-code-quality/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python Code Quality: Best Practices and Tools&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 Python code quality, tools, and best practices. By working through this quiz, you&#x27;ll revisit the importance of producing high-quality Python code that&#x27;s functional, readable, maintainable, efficient, and secure.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;defining-code-quality&quot;&gt;Defining Code Quality&lt;a class=&quot;headerlink&quot; href=&quot;#defining-code-quality&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Of course you want quality code. Who wouldn’t? But what is &lt;strong&gt;code quality&lt;/strong&gt;? It turns out that the term can mean different things to different people.&lt;/p&gt;
&lt;p&gt;One way to approach code quality is to look at the two ends of the quality spectrum:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Low-quality code&lt;/strong&gt;: It has the &lt;strong&gt;minimal required&lt;/strong&gt; characteristics to be &lt;strong&gt;functional&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High-quality code&lt;/strong&gt;: It has &lt;strong&gt;all the necessary&lt;/strong&gt; characteristics that make it work reliably, efficiently, and effectively, while also being straightforward to maintain.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the following sections, you’ll learn about these two quality classifications and their defining characteristics in more detail.&lt;/p&gt;
&lt;h3 id=&quot;low-quality-code&quot;&gt;Low-Quality Code&lt;a class=&quot;headerlink&quot; href=&quot;#low-quality-code&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Low-quality code typically has only the minimal required characteristics to be functional. It may not be elegant, efficient, or easy to maintain, but at the very least, it meets the following basic criteria:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It does what it’s supposed to do&lt;/strong&gt;. If the code doesn’t meet its requirements, then it isn’t quality code. You build software to perform a task. If it fails to do so, then it can’t be considered quality code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It doesn’t contain critical errors&lt;/strong&gt;. If the code has issues and errors or causes you problems, then you probably wouldn’t call it quality code. If it’s too low-quality and becomes unusable, then if falls below even basic quality standards and you may stop using it altogether.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While simplistic, these two characteristics are generally accepted as the baseline of functional but low-quality code. Low-quality code may work, but it often lacks readability, maintainability, and efficiency, making it difficult to scale or improve.&lt;/p&gt;
&lt;h3 id=&quot;high-quality-code&quot;&gt;High-Quality Code&lt;a class=&quot;headerlink&quot; href=&quot;#high-quality-code&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Now, here’s an extended list of the key characteristics that define high-quality code:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Functionality&lt;/strong&gt;: Works as expected and fulfills its intended purpose.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Readability&lt;/strong&gt;: Is easy for humans to understand.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Documentation&lt;/strong&gt;: Clearly explains its purpose and usage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Standards Compliance&lt;/strong&gt;: Adheres to conventions and guidelines, such as PEP 8.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reusability&lt;/strong&gt;: Can be used in different contexts without modification.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintainability&lt;/strong&gt;: Allows for modifications and extensions without introducing bugs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Robustness&lt;/strong&gt;: Handles errors and unexpected inputs effectively.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testability&lt;/strong&gt;: Can be easily verified for correctness.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficiency&lt;/strong&gt;: Optimizes time and resource usage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Handles increased data loads or complexity without degradation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: Protects against vulnerabilities and malicious inputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In short, &lt;strong&gt;high-quality code&lt;/strong&gt; is functional, readable, maintainable, and robust. It follows best practices, including clear naming, consistent coding style, modular design, proper error handling, and adherence to coding standards. It’s also well-documented and easy to test and scale. Finally, high-quality code is efficient and secure, ensuring reliability and safe use.&lt;/p&gt;
&lt;p&gt;All the characteristics above allow developers to understand, modify, and extend a Python codebase with minimal effort.&lt;/p&gt;
&lt;h3 id=&quot;the-importance-of-code-quality&quot;&gt;The Importance of Code Quality&lt;a class=&quot;headerlink&quot; href=&quot;#the-importance-of-code-quality&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To understand why code quality matters, you’ll revisit the characteristics of high-quality code from the previous section and examine their impact:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Functional code&lt;/strong&gt;: Ensures correct behavior and expected outcomes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Readable code&lt;/strong&gt;: Makes understanding and maintaining code easier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Documented code&lt;/strong&gt;: Clarifies the correct and recommended way for others to use it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compliant code&lt;/strong&gt;: Promotes consistency and allows collaboration.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reusable code&lt;/strong&gt;: Saves time by allowing code reuse.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintainable code&lt;/strong&gt;: Supports updates, improvements, and extensions with ease.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Robust code&lt;/strong&gt;: Minimizes crashes and produces fewer edge-case issues.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testable code&lt;/strong&gt;: Simplifies verification of correctness through code testing. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Efficient code&lt;/strong&gt;: Runs faster and conserves system resources.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalable code&lt;/strong&gt;: Supports growing projects and increasing data loads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Secure code&lt;/strong&gt;: Provides safeguards against system loopholes and compromised inputs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The quality of your code matters because it produces code that’s easier to understand, modify, and extend over time. It leads to faster debugging, smoother feature development, reduced costs, and better user satisfaction while ensuring security and scalability.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-code-quality/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-code-quality/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python Code Quality: Best Practices and Tools</title>
      <id>https://realpython.com/quizzes/python-code-quality/</id>
      <link href="https://realpython.com/quizzes/python-code-quality/"/>
      <updated>2025-03-24T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python code quality, tools, and best practices. By working through this quiz, you&#x27;ll revisit the importance of producing high-quality Python code that&#x27;s functional, readable, maintainable, efficient, and secure.</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-code-quality/&quot;&gt;Python Code Quality: Tools &amp;amp; Best Practices&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit the importance of producing high-quality Python code that&amp;rsquo;s functional, readable, maintainable, efficient, and secure. You&amp;rsquo;ll also review how to use tools such as linters, formatters, and profilers to help achieve these qualities.&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 #244: A Decade of Automating the Boring Stuff With Python</title>
      <id>https://realpython.com/podcasts/rpp/244/</id>
      <link href="https://realpython.com/podcasts/rpp/244/"/>
      <updated>2025-03-21T12:00:00+00:00</updated>
      <summary>What goes into updating one of the most popular books about working with Python? After a decade of changes in the Python landscape, what projects, libraries, and skills are relevant to an office worker? This week on the show, we speak with previous guest Al Sweigart about the third edition of &quot;Automate the Boring Stuff With Python.&quot;</summary>
      <content type="html">
        &lt;p&gt;What goes into updating one of the most popular books about working with Python? After a decade of changes in the Python landscape, what projects, libraries, and skills are relevant to an office worker? This week on the show, we speak with previous guest Al Sweigart about the third edition of &quot;Automate the Boring Stuff With Python.&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>Quiz: How to Strip Characters From a Python String</title>
      <id>https://realpython.com/quizzes/python-strip/</id>
      <link href="https://realpython.com/quizzes/python-strip/"/>
      <updated>2025-03-21T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s .strip(), .lstrip(), and .rstrip() methods, as well as .removeprefix() and .removesuffix(). These methods are useful for tasks like cleaning user input, standardizing filenames, and preparing data for storage.</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-strip/&quot;&gt;Python&amp;rsquo;s &lt;code&gt;.strip()&lt;/code&gt; method&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll also revisit the related methods &lt;code&gt;.lstrip()&lt;/code&gt; and &lt;code&gt;.rstrip()&lt;/code&gt;, as well as &lt;code&gt;.removeprefix()&lt;/code&gt; and &lt;code&gt;.removesuffix()&lt;/code&gt;. These methods are useful for tasks like cleaning user input, standardizing filenames, and preparing data for storage.&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>LangGraph: Build Stateful AI Agents in Python</title>
      <id>https://realpython.com/langgraph-python/</id>
      <link href="https://realpython.com/langgraph-python/"/>
      <updated>2025-03-19T14:00:00+00:00</updated>
      <summary>LangGraph is a versatile Python library designed for stateful, cyclic, and multi-actor Large Language Model (LLM) applications. This tutorial will give you an overview of LangGraph fundamentals through hands-on examples, and the tools needed to build your own LLM workflows and agents in LangGraph.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;LangGraph is a versatile Python library designed for stateful, cyclic, and multi-actor Large Language Model (LLM) applications. LangGraph builds upon its parent library, LangChain, and allows you to build sophisticated workflows that are capable of handling the complexities of real-world LLM applications.&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;You can use LangGraph to build LLM workflows by &lt;strong&gt;defining state graphs with nodes and edges&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;LangGraph expands LangChain’s capabilities by providing tools to build complex LLM workflows with &lt;strong&gt;state, conditional edges, and cycles&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LLM agents&lt;/strong&gt; in LangGraph autonomously process tasks using state graphs to make decisions and interact with tools or APIs.&lt;/li&gt;
&lt;li&gt;You can use LangGraph independently of LangChain, although they’re often used together to complement each other.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Explore the full tutorial to gain hands-on experience with LangGraph, including setting up workflows and building a LangGraph agent that can autonomously parse emails, send emails, and interact with API services. &lt;/p&gt;
&lt;p&gt;While you’ll get a brief primer on &lt;a href=&quot;https://realpython.com/build-llm-rag-chatbot-with-langchain/&quot;&gt;LangChain&lt;/a&gt; in this tutorial, you’ll benefit from having prior knowledge of LangChain fundamentals. You’ll also want to ensure you have intermediate Python knowledge—specifically in &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt; concepts like classes and methods.&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/langgraph-python-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-langgraph-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 build stateful AI agents with LangGraph 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.6eec2e95bede.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 “LangGraph: Build Stateful AI Agents 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/langgraph-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: #abe5b2;&quot; alt=&quot;LangGraph: Build Stateful AI Agents in Python&quot; src=&quot;https://files.realpython.com/media/Showcase-Langgraph_Watermarked.6435fda68bc4.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Showcase-Langgraph_Watermarked.6435fda68bc4.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Showcase-Langgraph_Watermarked.6435fda68bc4.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Showcase-Langgraph_Watermarked.6435fda68bc4.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Showcase-Langgraph_Watermarked.6435fda68bc4.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.6eec2e95bede.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/langgraph-python/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;LangGraph: Build Stateful AI Agents in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Take this quiz to test your understanding of LangGraph, a Python library designed for stateful, cyclic, and multi-actor Large Language Model (LLM) applications. By working through this quiz, you&#x27;ll revisit how to build LLM workflows and agents in LangGraph.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;install-langgraph&quot;&gt;Install LangGraph&lt;a class=&quot;headerlink&quot; href=&quot;#install-langgraph&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;LangGraph is available on &lt;a href=&quot;https://pypi.org/&quot;&gt;PyPI&lt;/a&gt;, and you can install it with &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;&lt;code&gt;pip&lt;/code&gt;&lt;/a&gt;. Open a terminal or command prompt, create a new virtual environment, and then run the following command:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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 gp-VirtualEnv&quot;&gt;(venv)&lt;/span&gt; &lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;langgraph
&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.6eec2e95bede.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.6eec2e95bede.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 command will install the latest version of LangGraph from PyPI onto your machine. To verify that the installation was successful, start a &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python REPL&lt;/a&gt; and import LangGraph:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;langgraph&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.6eec2e95bede.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.6eec2e95bede.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;If the import runs without error, then you’ve successfully installed LangGraph. You’ll also need a few more libraries for this tutorial:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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 gp-VirtualEnv&quot;&gt;(venv)&lt;/span&gt; &lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;langchain-openai&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;pydantic[email]&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.6eec2e95bede.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.6eec2e95bede.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 use &lt;code&gt;langchain-openai&lt;/code&gt; to interact with OpenAI LLMs, but keep in mind that you can use any LLM provider you like with LangGraph and LangChain. You’ll use &lt;a href=&quot;https://realpython.com/python-pydantic/&quot;&gt;&lt;code&gt;pydantic&lt;/code&gt;&lt;/a&gt; to validate the information your agent parses from emails.&lt;/p&gt;
&lt;p&gt;Before moving forward, if you choose to use OpenAI, make sure you’re signed up for an OpenAI account and that you have a valid &lt;a href=&quot;https://openai.com/api/&quot;&gt;API key&lt;/a&gt;. You’ll need to set the following &lt;a href=&quot;https://en.wikipedia.org/wiki/Environment_variable&quot;&gt;environment variable&lt;/a&gt; before running any examples in this tutorial:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;dotenv&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--grey&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;.env&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;na&quot;&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;YOUR-OPENAI-API-KEY&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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.6eec2e95bede.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;Note that while LangGraph was made by the creators of LangChain, and the two libraries are highly compatible, it’s possible to use LangGraph without LangChain. However, it’s more common to use LangChain and LangGraph together, and you’ll see throughout this tutorial how they complement each other.&lt;/p&gt;
&lt;p&gt;With that, you’ve installed all the dependencies you’ll need for this tutorial, and you’re ready to create your LangGraph email processor. Before diving in, you’ll take a brief detour to set up quick sanity tests for your app. Then, you’ll go through an overview of LangChain chains and explore LangGraph’s core concept—the state graph.&lt;/p&gt;
&lt;h2 id=&quot;create-test-cases&quot;&gt;Create Test Cases&lt;a class=&quot;headerlink&quot; href=&quot;#create-test-cases&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;When developing AI applications, testing and performance tracking is crucial for understanding how your chain, graph, or agent performs in the real world. While performance tracking is out of scope for this tutorial, you’ll use several example emails to test your chains, graphs, and agent, and you’ll empirically inspect whether their outputs are correct. &lt;/p&gt;
&lt;p&gt;To avoid redefining these examples each time, create the following Python file with example emails:&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;example_emails.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;EMAILS&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;c1&quot;&gt;# Email 0&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;    Date: October 15, 2024&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    From: Occupational Safety and Health Administration (OSHA)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    To: Blue Ridge Construction, project 111232345 - Downtown Office&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Complex Location: Dallas, TX&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    During a recent inspection of your construction site at 123 Main&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Street,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    the following safety violations were identified:&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    Lack of fall protection: Workers on scaffolding above 10 feet&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    were without required harnesses or other fall protection&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    equipment. Unsafe scaffolding setup: Several scaffolding&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    structures were noted as&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    lacking secure base plates and bracing, creating potential&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    collapse risks.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Inadequate personal protective equipment (PPE): Multiple&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    workers were&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    found without proper PPE, including hard hats and safety&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    glasses.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Required Corrective Actions:&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    Install guardrails and fall arrest systems on all scaffolding&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    over 10 feet. Conduct an inspection of all scaffolding&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    structures and reinforce unstable sections. Ensure all&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    workers on-site are provided&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    with necessary PPE and conduct safety training on proper&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    usage.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Deadline for Compliance: All violations must be rectified&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    by November 10, 2024. Failure to comply may result in fines&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    of up to&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    $25,000 per violation.&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    Contact: For questions or to confirm compliance, please reach&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    out to the&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    OSHA regional office at (555) 123-4567 or email&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    compliance.osha@osha.gov.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Email 1&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;    From: debby@stack.com&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Hey Betsy,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Here&#x27;s your invoice for $1000 for the cookies you ordered.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Email 2&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;    From: tdavid@companyxyz.com&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Hi Paul,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    We have an issue with the HVAC system your team installed in&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    apartment 1235. We&#x27;d like to request maintenance or a refund.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Thanks,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Terrance&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Email 3&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;    Date: January 10, 2025&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    From: City of Los Angeles Building and Safety Department&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    To: West Coast Development, project 345678123 - Sunset Luxury&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Condominiums&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Location: Los Angeles, CA&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Following an inspection of your site at 456 Sunset Boulevard, we have&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    identified the following building code violations:&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Electrical Wiring: Exposed wiring was found in the underground parking&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    garage, posing a safety hazard. Fire Safety: Insufficient fire&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    extinguishers were available across multiple floors of the structure&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    under construction.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Structural Integrity: The temporary support beams in the eastern wing&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    do not meet the load-bearing standards specified in local building&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    codes.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Required Corrective Actions:&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Replace or properly secure exposed wiring to meet electrical safety&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    standards. Install additional fire extinguishers in compliance with&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    fire code requirements. Reinforce or replace temporary support beams&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    to ensure structural stability. Deadline for Compliance: Violations&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    must be addressed no later than February 5,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    2025. Failure to comply may result in&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    a stop-work order and additional fines.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Contact: For questions or to schedule a re-inspection, please contact&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    the Building and Safety Department at&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    (555) 456-7890 or email inspections@lacity.gov.&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&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.6eec2e95bede.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.6eec2e95bede.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 read through these right now if you want, but you’ll get links back to these test emails throughout the tutorial.&lt;/p&gt;
&lt;h2 id=&quot;work-with-state-graphs&quot;&gt;Work With State Graphs&lt;a class=&quot;headerlink&quot; href=&quot;#work-with-state-graphs&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/langgraph-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/langgraph-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: Python&#x27;s Bytearray</title>
      <id>https://realpython.com/quizzes/python-bytearray/</id>
      <link href="https://realpython.com/quizzes/python-bytearray/"/>
      <updated>2025-03-19T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s bytearray data type. By working through this quiz, you&#x27;ll revisit the key concepts and uses of bytearray in Python.</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-bytearray/&quot;&gt;Python&amp;rsquo;s Bytearray: A Mutable Sequence of Bytes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit the key concepts and uses of &lt;code&gt;bytearray&lt;/code&gt; in Python.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Using Structural Pattern Matching in Python</title>
      <id>https://realpython.com/courses/structural-pattern-matching/</id>
      <link href="https://realpython.com/courses/structural-pattern-matching/"/>
      <updated>2025-03-18T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to harness the power of structural pattern matching in Python. You&#x27;ll explore the new syntax, delve into various pattern types, and find appropriate applications for pattern matching, all while identifying common pitfalls.</summary>
      <content type="html">
        &lt;p&gt;Structural pattern matching is a powerful &lt;strong&gt;control flow construct&lt;/strong&gt; invented decades ago that&amp;rsquo;s traditionally used by compiled languages, especially within the &lt;a href=&quot;https://realpython.com/python-functional-programming/&quot;&gt;functional programming paradigm&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Most mainstream programming languages have since adopted some form of pattern matching, which offers concise and readable syntax while promoting a declarative code style. Although Python was late to join the party, it introduced structural pattern matching in the &lt;a href=&quot;https://realpython.com/python310-new-features/&quot;&gt;3.10&lt;/a&gt; release.&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;Master the &lt;strong&gt;syntax&lt;/strong&gt; of the &lt;code&gt;match&lt;/code&gt; statement and &lt;code&gt;case&lt;/code&gt; clauses&lt;/li&gt;
&lt;li&gt;Explore various &lt;strong&gt;types of patterns&lt;/strong&gt; supported by Python&lt;/li&gt;
&lt;li&gt;Learn about &lt;strong&gt;guards&lt;/strong&gt;, &lt;strong&gt;unions&lt;/strong&gt;, &lt;strong&gt;aliases&lt;/strong&gt;, and &lt;strong&gt;name binding&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Extract values from deeply nested &lt;strong&gt;hierarchical data structures&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Customize pattern matching for &lt;strong&gt;user-defined classes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Identify and avoid &lt;strong&gt;common pitfalls&lt;/strong&gt; in Python&amp;rsquo;s pattern matching&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&#x27;s Instance, Class, and Static Methods Demystified</title>
      <id>https://realpython.com/instance-class-and-static-methods-demystified/</id>
      <link href="https://realpython.com/instance-class-and-static-methods-demystified/"/>
      <updated>2025-03-17T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll compare Python&#x27;s instance methods, class methods, and static methods. You&#x27;ll gain an understanding of when and how to use each method type to write clear and maintainable object-oriented code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Instance, class, and static methods each serve a distinct role in Python, and knowing when to use one over another is key to writing clean, maintainable code. Instance methods operate on individual objects using &lt;code&gt;self&lt;/code&gt;, while class methods use &lt;code&gt;cls&lt;/code&gt; to access class-level data. Static methods, on the other hand, provide organizational structure without relying on class or instance state. &lt;/p&gt;
&lt;p&gt;When you understand the differences between these three method types, you’ll be in a better spot to know when to write an instance method, class method, or a static method. Ultimately, this’ll help you design better maintainable object-oriented Python code.&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;Instance methods&lt;/strong&gt; access the state of a &lt;strong&gt;specific object&lt;/strong&gt; through the &lt;strong&gt;&lt;code&gt;self&lt;/code&gt;&lt;/strong&gt; parameter.&lt;/li&gt;
&lt;li&gt;You create &lt;strong&gt;class methods&lt;/strong&gt; with the &lt;strong&gt;&lt;code&gt;@classmethod&lt;/code&gt;&lt;/strong&gt; decorator and use them for operations that involve &lt;strong&gt;class-level data&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You use &lt;strong&gt;static methods&lt;/strong&gt; for &lt;strong&gt;utility functionality&lt;/strong&gt; that doesn’t need class or instance data, and you create them with the &lt;strong&gt;&lt;code&gt;@staticmethod&lt;/code&gt;&lt;/strong&gt; decorator.&lt;/li&gt;
&lt;li&gt;Using class methods and static methods in your classes can &lt;strong&gt;improve class design&lt;/strong&gt; and code maintainability.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Keep reading to see all three method types in action. You’ll even bake some digital pizza while working on a real-world example with all three method types in a &lt;code&gt;Pizza&lt;/code&gt; class.
If you develop an intuitive understanding for their differences, you’ll be able to write &lt;a href=&quot;/ref/glossary/oop/&quot; class=&quot;ref-link&quot;&gt;object-oriented&lt;/a&gt; Python code that communicates its intent more clearly and is easier to maintain in the long run.&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/instance-class-and-static-methods-demystified-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-instance-class-and-static-methods-demystified-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code &lt;/a&gt; you’ll use to learn about instance, class, and static methods 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.6eec2e95bede.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 Instance, Class, and Static Methods Demystified” 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/instance-class-and-static-methods-demystified/&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;Python classmethods, staticmethods, and instance methods&quot; src=&quot;https://files.realpython.com/media/Pythons-Instance-Class-and-Static-Methods-Demystified_Watermarked.5bce71bc29d0.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Pythons-Instance-Class-and-Static-Methods-Demystified_Watermarked.5bce71bc29d0.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Pythons-Instance-Class-and-Static-Methods-Demystified_Watermarked.5bce71bc29d0.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Pythons-Instance-Class-and-Static-Methods-Demystified_Watermarked.5bce71bc29d0.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Pythons-Instance-Class-and-Static-Methods-Demystified_Watermarked.5bce71bc29d0.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.6eec2e95bede.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/instance-class-and-static-methods-demystified/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python&#x27;s Instance, Class, and Static Methods Demystified&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 instance, class, and static methods in Python. By working through this quiz, you&#x27;ll revisit the differences between these methods and how to use them effectively in your Python code.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;compare-instance-methods-vs-class-methods-vs-static-methods&quot;&gt;Compare Instance Methods vs Class Methods vs Static Methods&lt;a class=&quot;headerlink&quot; href=&quot;#compare-instance-methods-vs-class-methods-vs-static-methods&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you’re here for a quick reminder of how the three method types differ from one another, then consider the following overview that compares them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Instance methods&lt;/strong&gt; use a &lt;code&gt;self&lt;/code&gt; parameter pointing to an &lt;a href=&quot;/ref/glossary/instance/&quot; class=&quot;ref-link&quot;&gt;instance&lt;/a&gt; of the &lt;a href=&quot;/ref/glossary/class/&quot; class=&quot;ref-link&quot;&gt;class&lt;/a&gt;. They can access and modify instance state through &lt;code&gt;self&lt;/code&gt; and class state through &lt;code&gt;self.__class__&lt;/code&gt;. These are the most common methods in Python classes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Class methods&lt;/strong&gt; use a &lt;code&gt;cls&lt;/code&gt; parameter pointing to the class itself. They can modify class-level state through &lt;code&gt;cls&lt;/code&gt;, but they can’t modify individual instance state.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Static methods&lt;/strong&gt; don’t take &lt;code&gt;self&lt;/code&gt; or &lt;code&gt;cls&lt;/code&gt; parameters. They can’t modify instance or class state directly, and you’ll mainly use them for organizational purposes and namespacing.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you need to revisit information quickly, there’s nothing quite like a table. So here are the most important aspects of the three different types of methods in Python classes summed up in a table:&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;Type&lt;/th&gt;
&lt;th&gt;Decorator&lt;/th&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Instance Access&lt;/th&gt;
&lt;th&gt;Class Access&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Instance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;None needed&lt;/td&gt;
&lt;td&gt;&lt;code&gt;self&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Operations on individual instances.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Class&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@classmethod&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;cls&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;Factory methods, alternative constructors, or any method that deals with class-level data.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Static&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;@staticmethod&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No &lt;code&gt;self&lt;/code&gt; or &lt;code&gt;cls&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;Utility methods that don’t need instance or class data.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;That’s enough super-condensed, repetitive reference information! If you want to know what all of this means in practice, and you like to learn by running code snippets and reasoning about them, then keep on reading.&lt;/p&gt;
&lt;p&gt;Next, you’ll explore the differences between instance, class, and static methods in a somewhat abstract code example. Abstract you say? Don’t worry—it involves runnable code, and it’s there to set the stage for a more practical example later on.&lt;/p&gt;
&lt;h2 id=&quot;gain-insight-through-an-abstract-example&quot;&gt;Gain Insight Through an Abstract Example&lt;a class=&quot;headerlink&quot; href=&quot;#gain-insight-through-an-abstract-example&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To get warmed up, you’ll write a small Python file called &lt;code&gt;demo.py&lt;/code&gt; with a bare-bones Python class that contains stripped-down examples of all three method types:&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;demo.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;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;DemoClass&lt;/span&gt;&lt;span class=&quot;p&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;instance_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;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;instance method called&quot;&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;nd&quot;&gt;@classmethod&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;class_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;cls&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;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;class method called&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;cls&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@staticmethod&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;static_method&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;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;static method called&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.6eec2e95bede.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.6eec2e95bede.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;Inside &lt;code&gt;demo.py&lt;/code&gt;, you create &lt;code&gt;DemoClass&lt;/code&gt;—a descriptively named custom class with the sole purpose of demoing the differences between instance methods, class methods, and static methods.&lt;/p&gt;
&lt;p&gt;Consequently, you also implement one of each of the three method types and name them accordingly. They each return a &lt;a href=&quot;https://realpython.com/python-tuple/&quot;&gt;tuple&lt;/a&gt; containing information to help you trace what’s going on, as well as the arguments the method received, such as &lt;code&gt;self&lt;/code&gt; and &lt;code&gt;cls&lt;/code&gt;. The output will help you understand which &lt;a href=&quot;/ref/glossary/object/&quot; class=&quot;ref-link&quot;&gt;objects&lt;/a&gt; each of the methods can access.&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; Naming these parameters &lt;code&gt;self&lt;/code&gt; and &lt;code&gt;cls&lt;/code&gt; is just a convention—but it’s a strong one in the Python community! You could name them &lt;code&gt;foo&lt;/code&gt; and &lt;code&gt;bar&lt;/code&gt; and get the same result. However, if you stray from the convention, then you may get disapproving looks from your coworkers or anyone reading your code.&lt;/p&gt;
&lt;p&gt;For functionality, all that matters is that you position them first in the parameter list for the method. For maintainability, sanity, and out of respect for others, you should always use &lt;code&gt;self&lt;/code&gt; and &lt;code&gt;cls&lt;/code&gt; in the classes you define.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now it’s time to call these demo methods in a new &lt;a href=&quot;/ref/glossary/repl/&quot; class=&quot;ref-link&quot;&gt;REPL&lt;/a&gt; session. Import &lt;code&gt;DemoClass&lt;/code&gt; and create an instance of it, then start by calling the &lt;strong&gt;instance method&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;demo&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DemoClass&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;obj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DemoClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&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;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;instance_method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(&#x27;instance method called&#x27;, &amp;lt;demo.DemoClass object at 0x100a30d70&amp;gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.6eec2e95bede.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.6eec2e95bede.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The output confirms that &lt;code&gt;.instance_method()&lt;/code&gt; has access to the object instance through the &lt;code&gt;self&lt;/code&gt; argument. Python prints the object instance as &lt;code&gt;&amp;lt;demo.DemoClass object at 0x100a30d70&amp;gt;&lt;/code&gt;. When you call the instance method, Python replaces the &lt;code&gt;self&lt;/code&gt; argument with the instance object, &lt;code&gt;obj&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Instance methods can also access the class itself through the &lt;code&gt;self.__class__&lt;/code&gt; attribute. This makes instance methods powerful in terms of access restrictions. They can modify state on the object instance &lt;em&gt;and&lt;/em&gt; on the class itself.&lt;/p&gt;
&lt;p&gt;Next, you can try out the &lt;strong&gt;class method&lt;/strong&gt;:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/instance-class-and-static-methods-demystified/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/instance-class-and-static-methods-demystified/ »&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 #243: Manage Projects With pyproject.toml &amp; Explore Polars LazyFrames</title>
      <id>https://realpython.com/podcasts/rpp/243/</id>
      <link href="https://realpython.com/podcasts/rpp/243/"/>
      <updated>2025-03-14T12:00:00+00:00</updated>
      <summary>How can you simplify the management of your Python projects with one file? What are the advantages of using LazyFrames in Polars? 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 can you simplify the management of your Python projects with one file? What are the advantages of using LazyFrames in Polars? 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>Getting to Know Duck Typing in Python</title>
      <id>https://realpython.com/courses/duck-typing-python/</id>
      <link href="https://realpython.com/courses/duck-typing-python/"/>
      <updated>2025-03-11T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn about duck typing in Python---a type system based on an object&#x27;s behavior rather than inheritance. By taking advantage of duck typing, you can create flexible and decoupled sets of Python classes that work together or independently.</summary>
      <content type="html">
        &lt;p&gt;Python makes extensive use of a &lt;a href=&quot;https://realpython.com/python-type-checking/#type-systems&quot;&gt;type system&lt;/a&gt; known as &lt;strong&gt;duck typing&lt;/strong&gt;. This system is based on an object&amp;rsquo;s behavior and interface. Many built-in classes and tools support this type system, which makes them pretty flexible and decoupled.&lt;/p&gt;
&lt;p&gt;Duck typing is a core concept in Python. Understanding it will give you deeper insight into how the language works and, more importantly, how to use this approach in your own code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What &lt;strong&gt;duck typing&lt;/strong&gt; is and what its pros and cons are&lt;/li&gt;
&lt;li&gt;How Python&amp;rsquo;s classes and tools &lt;strong&gt;take advantage of duck typing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How &lt;strong&gt;special methods&lt;/strong&gt; and &lt;strong&gt;protocols&lt;/strong&gt; support duck typing&lt;/li&gt;
&lt;li&gt;What the &lt;strong&gt;alternatives&lt;/strong&gt; to duck typing are in Python&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 #242: Eric Matthes: Maybe Don&#x27;t Start With Unit Tests</title>
      <id>https://realpython.com/podcasts/rpp/242/</id>
      <link href="https://realpython.com/podcasts/rpp/242/"/>
      <updated>2025-03-07T12:00:00+00:00</updated>
      <summary>Should you always start testing your code with unit tests? When does it make sense to look at integration or end-to-end testing as a first step instead? This week on the show, we speak with previous guest Eric Matthes about where to begin testing your code.</summary>
      <content type="html">
        &lt;p&gt;Should you always start testing your code with unit tests? When does it make sense to look at integration or end-to-end testing as a first step instead? This week on the show, we speak with previous guest Eric Matthes about where to begin testing your code.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Working With Python Polars</title>
      <id>https://realpython.com/courses/working-with-python-polars/</id>
      <link href="https://realpython.com/courses/working-with-python-polars/"/>
      <updated>2025-03-04T14:00:00+00:00</updated>
      <summary>Welcome to the world of Polars, a powerful DataFrame library for Python. In this video course, you&#x27;ll get a hands-on introduction to Polars&#x27; core features and see why this library is catching so much buzz.</summary>
      <content type="html">
        &lt;p&gt;In the world of data analysis and manipulation, Python has long been the go-to language. With extensive and user-friendly libraries like &lt;a href=&quot;https://realpython.com/numpy-tutorial/&quot;&gt;NumPy&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/learning-paths/pandas-data-science/&quot;&gt;pandas&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/pyspark-intro/&quot;&gt;PySpark&lt;/a&gt;, there&amp;rsquo;s a solution available for almost any data-driven task. Among these libraries, one name that&amp;rsquo;s been generating a significant amount of buzz lately is &lt;a href=&quot;https://pola-rs.github.io/polars-book/&quot;&gt;Polars&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Polars is a high-performance DataFrame library, designed to provide fast and efficient data processing capabilities. Inspired by the reigning pandas library, Polars takes things to another level, offering a seamless experience for working with large datasets that might not fit into memory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Why Polars is so &lt;strong&gt;performant&lt;/strong&gt; and attention-grabbing&lt;/li&gt;
&lt;li&gt;How to work with &lt;strong&gt;DataFrames&lt;/strong&gt;, &lt;strong&gt;expressions&lt;/strong&gt;, and &lt;strong&gt;contexts&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;read&lt;/strong&gt; data into &lt;strong&gt;DataFrames&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;group&lt;/strong&gt; and &lt;strong&gt;aggregate&lt;/strong&gt; data &lt;/li&gt;
&lt;li&gt;What the &lt;strong&gt;lazy API&lt;/strong&gt; is and how to build &lt;strong&gt;lazy queries&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 #241: Deciphering Python Jargon &amp; Compiling Python 1.0</title>
      <id>https://realpython.com/podcasts/rpp/241/</id>
      <link href="https://realpython.com/podcasts/rpp/241/"/>
      <updated>2025-02-28T12:00:00+00:00</updated>
      <summary>How do you learn the terms commonly used when speaking about Python? How is the jargon similar to other programming languages? 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 do you learn the terms commonly used when speaking about Python? How is the jargon similar to other programming languages? 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>Single and Double Underscore Naming Conventions in Python</title>
      <id>https://realpython.com/courses/single-double-underscore-naming-conventions/</id>
      <link href="https://realpython.com/courses/single-double-underscore-naming-conventions/"/>
      <updated>2025-02-25T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn a few Python naming conventions involving single and double underscores (_). You&#x27;ll learn how to use this character to differentiate between public and non-public names in APIs, write safe classes for subclassing purposes, avoid name clashes, and more.</summary>
      <content type="html">
        &lt;p&gt;Python has a few important &lt;strong&gt;naming conventions&lt;/strong&gt; that are based on using either a single or double &lt;strong&gt;underscore&lt;/strong&gt; character (&lt;code&gt;_&lt;/code&gt;). These conventions allow you to differentiate between public and non-public names in APIs, write safe classes for subclassing purposes, avoid name clashes, and more.&lt;/p&gt;
&lt;p&gt;Following and respecting these conventions allows you to write code that looks Pythonic and consistent in the eyes of other Python developers. This skill is especially useful when you&amp;rsquo;re writing code that&amp;rsquo;s intended for other developers to work with.&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 about Python &lt;strong&gt;naming conventions&lt;/strong&gt; that rely on using &lt;strong&gt;underscores&lt;/strong&gt; (&lt;code&gt;_&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Differentiate &lt;strong&gt;public&lt;/strong&gt; and &lt;strong&gt;non-public&lt;/strong&gt; names by using a single leading underscore&lt;/li&gt;
&lt;li&gt;Use double leading underscores to leverage &lt;strong&gt;name mangling&lt;/strong&gt; in Python classes&lt;/li&gt;
&lt;li&gt;Explore other &lt;strong&gt;common uses&lt;/strong&gt; of underscores in Python names&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 #240: Telling Effective Stories With Your Python Visualizations</title>
      <id>https://realpython.com/podcasts/rpp/240/</id>
      <link href="https://realpython.com/podcasts/rpp/240/"/>
      <updated>2025-02-21T12:00:00+00:00</updated>
      <summary>How do you make compelling visualizations that best convey the story of your data? What methods can you employ within popular Python tools to improve your plots and graphs? This week on the show, Matt Harrison returns to discuss his new book &quot;Effective Visualization: Exploiting Matplotlib &amp; Pandas.&quot;</summary>
      <content type="html">
        &lt;p&gt;How do you make compelling visualizations that best convey the story of your data? What methods can you employ within popular Python tools to improve your plots and graphs? This week on the show, Matt Harrison returns to discuss his new book &quot;Effective Visualization: Exploiting Matplotlib &amp; Pandas.&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>Concatenating Strings in Python Efficiently</title>
      <id>https://realpython.com/courses/concatenating-strings-efficiently/</id>
      <link href="https://realpython.com/courses/concatenating-strings-efficiently/"/>
      <updated>2025-02-18T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to concatenate strings in Python. You&#x27;ll use different tools and techniques for string concatenation, including the concatenation operators and the .join() method. You&#x27;ll also explore other tools that can also be handy for string concatenation in Python.</summary>
      <content type="html">
        &lt;p&gt;Python &lt;strong&gt;string concatenation&lt;/strong&gt; is a fundamental operation that combines multiple strings into a single string. In Python, you can concatenate strings using the &lt;code&gt;+&lt;/code&gt; operator or append them with &lt;code&gt;+=&lt;/code&gt;. For more efficient concatenation, especially when working with lists of strings, the &lt;code&gt;.join()&lt;/code&gt; method is recommended. Other techniques include using &lt;code&gt;StringIO&lt;/code&gt; for large datasets and the &lt;code&gt;print()&lt;/code&gt; function for quick screen output.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that you can:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Concatenate strings&lt;/strong&gt; in Python using the &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;+=&lt;/code&gt; operators.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;+=&lt;/code&gt; to &lt;strong&gt;append a string&lt;/strong&gt; to an existing string.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;.join()&lt;/code&gt; method to &lt;strong&gt;combine strings in a list&lt;/strong&gt; in Python.&lt;/li&gt;
&lt;li&gt;Handle a &lt;strong&gt;stream of strings&lt;/strong&gt; efficiently by using &lt;code&gt;StringIO&lt;/code&gt; as a container with a file-like interface.&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 #239: Behavior-Driven vs Test-Driven Development &amp; Using Regex in Python</title>
      <id>https://realpython.com/podcasts/rpp/239/</id>
      <link href="https://realpython.com/podcasts/rpp/239/"/>
      <updated>2025-02-14T12:00:00+00:00</updated>
      <summary>What is behavior-driven development, and how does it work alongside test-driven development? How do you communicate requirements between teams in an organization? 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 behavior-driven development, and how does it work alongside test-driven development? How do you communicate requirements between teams in an organization? 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>Building a Python Command-Line To-Do App With Typer</title>
      <id>https://realpython.com/courses/build-command-line-todo-app-typer/</id>
      <link href="https://realpython.com/courses/build-command-line-todo-app-typer/"/>
      <updated>2025-02-11T14:00:00+00:00</updated>
      <summary>In this step-by-step video course, you&#x27;ll create a to-do application for your command line using Python and Typer. While you build this app, you&#x27;ll learn the basics of Typer, a modern and versatile library for building command-line interfaces (CLI).</summary>
      <content type="html">
        &lt;p&gt;Building an application to manage your &lt;strong&gt;to-do list&lt;/strong&gt; can be an interesting project when you&amp;rsquo;re learning a new programming language or trying to take your skills to the next level. In this video course, you&amp;rsquo;ll build a functional to-do application for the command line using Python and &lt;a href=&quot;https://typer.tiangolo.com/&quot;&gt;Typer&lt;/a&gt;, which is a relatively young library for creating powerful command-line interface (CLI) applications in almost no time.&lt;/p&gt;
&lt;p&gt;With a project like this, you&amp;rsquo;ll apply a wide set of core programming skills while building a real-world application with real features and requirements.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Build a functional &lt;strong&gt;to-do application&lt;/strong&gt; with a &lt;strong&gt;Typer CLI&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;Use Typer to add &lt;strong&gt;commands&lt;/strong&gt;, &lt;strong&gt;arguments&lt;/strong&gt;, and &lt;strong&gt;options&lt;/strong&gt; to your to-do app&lt;/li&gt;
&lt;li&gt;Test your Python to-do application with Typer&amp;rsquo;s &lt;strong&gt;&lt;code&gt;CliRunner&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;pytest&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 #238: Charlie Marsh: Accelerating Python Tooling With Ruff and uv</title>
      <id>https://realpython.com/podcasts/rpp/238/</id>
      <link href="https://realpython.com/podcasts/rpp/238/"/>
      <updated>2025-02-07T12:00:00+00:00</updated>
      <summary>Are you looking for fast tools to lint your code and manage your projects? How is the Rust programming language being used to speed up Python tools? This week on the show, we speak with Charlie Marsh about his company, Astral, and their tools, uv and Ruff.</summary>
      <content type="html">
        &lt;p&gt;Are you looking for fast tools to lint your code and manage your projects? How is the Rust programming language being used to speed up Python tools? This week on the show, we speak with Charlie Marsh about his company, Astral, and their tools, uv and Ruff.&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>
