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

  
    <entry>
      <title>The Real Python Podcast – Episode #255: Structuring Python Scripts &amp; Exciting Non-LLM Software Trends</title>
      <id>https://realpython.com/podcasts/rpp/255/</id>
      <link href="https://realpython.com/podcasts/rpp/255/"/>
      <updated>2025-06-27T12:00:00+00:00</updated>
      <summary>What goes into crafting an effective Python script? How do you organize your code, manage dependencies with PEP 723, and handle command-line arguments for the best results? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What goes into crafting an effective Python script? How do you organize your code, manage dependencies with PEP 723, and handle command-line arguments for the best results? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Your Guide to the Python print() Function</title>
      <id>https://realpython.com/python-print/</id>
      <link href="https://realpython.com/python-print/"/>
      <updated>2025-06-25T14:00:00+00:00</updated>
      <summary>Learn how Python&#x27;s print() function works, avoid common pitfalls, and explore powerful alternatives and hidden features that can improve your code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;If you’re like most Python users, then you probably started your Python journey by learning about &lt;code&gt;print()&lt;/code&gt;. It helped you write your very own “Hello, World!” one-liner and brought your code to life on the screen. Beyond that, you can use it to format messages and even find some bugs. But if you think that’s all there is to know about Python’s &lt;code&gt;print()&lt;/code&gt; function, then you’re missing out on a lot!&lt;/p&gt;
&lt;p&gt;Keep reading to take full advantage of this seemingly boring and unappreciated little function. This tutorial will get you up to speed with using Python &lt;code&gt;print()&lt;/code&gt; effectively. However, be prepared for a deep dive as you go through the sections. You may be surprised by how much &lt;code&gt;print()&lt;/code&gt; has to offer!&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;print()&lt;/code&gt; function can handle &lt;strong&gt;multiple arguments&lt;/strong&gt; and &lt;strong&gt;custom separators&lt;/strong&gt; to format output effectively.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;redirect&lt;/strong&gt; &lt;code&gt;print()&lt;/code&gt; output to &lt;strong&gt;files&lt;/strong&gt; or &lt;strong&gt;memory buffers&lt;/strong&gt; using the &lt;code&gt;file&lt;/code&gt; argument, enhancing flexibility.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mocking&lt;/strong&gt; &lt;code&gt;print()&lt;/code&gt; in &lt;strong&gt;unit tests&lt;/strong&gt; helps verify code behavior without altering the original function.&lt;/li&gt;
&lt;li&gt;Using the &lt;code&gt;flush&lt;/code&gt; argument ensures immediate output, overcoming &lt;strong&gt;buffering delays&lt;/strong&gt; in certain environments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Thread-safe printing&lt;/strong&gt; is achievable by implementing locks to prevent output interleaving.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you’re just &lt;a href=&quot;https://realpython.com/python-beginner-tips/&quot;&gt;getting started with Python&lt;/a&gt;, then you’ll benefit most from reading the first part of this tutorial, which illustrates the essentials of printing in Python. Otherwise, feel free to skip ahead and explore the sections that interest you the most.&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-print-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-print-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 the print() function 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.437b3be14035.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 “The Python print() Function” 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-print-guide/&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;The Ultimate Guide to Python Print&quot; src=&quot;https://files.realpython.com/media/The-Python-Print-Function_Watermarked.26066d64ad82.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/The-Python-Print-Function_Watermarked.26066d64ad82.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/The-Python-Print-Function_Watermarked.26066d64ad82.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/The-Python-Print-Function_Watermarked.26066d64ad82.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/The-Python-Print-Function_Watermarked.26066d64ad82.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.437b3be14035.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-print-guide/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;The Python print() Function&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 built-in print() function, covering how to format output, specify custom separators, and more.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;printing-in-a-nutshell&quot;&gt;Printing in a Nutshell&lt;a class=&quot;headerlink&quot; href=&quot;#printing-in-a-nutshell&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It’s time to jump in by looking at a few real-life examples of printing in Python. By the end of this section, you’ll know every possible way of calling &lt;code&gt;print()&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;producing-blank-lines&quot;&gt;Producing Blank Lines&lt;a class=&quot;headerlink&quot; href=&quot;#producing-blank-lines&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The simplest example of using Python &lt;code&gt;print()&lt;/code&gt; requires just a few keystrokes:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;print&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.437b3be14035.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.437b3be14035.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 produces an invisible &lt;a href=&quot;https://en.wikipedia.org/wiki/Newline&quot;&gt;newline character&lt;/a&gt;, which in turn causes a &lt;strong&gt;blank line&lt;/strong&gt; to appear on your screen. To add vertical space, you can call &lt;code&gt;print()&lt;/code&gt; multiple times in a row like this:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;print&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.437b3be14035.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.437b3be14035.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;It’s just as if you were hitting &lt;span class=&quot;keys&quot;&gt;&lt;kbd class=&quot;key-enter&quot;&gt;Enter&lt;/kbd&gt;&lt;/span&gt; on your keyboard in a &lt;a href=&quot;https://en.wikipedia.org/wiki/Word_processor_program&quot;&gt;word processor program&lt;/a&gt; or a text editor.&lt;/p&gt;
&lt;p&gt;While you don’t pass any arguments to &lt;code&gt;print()&lt;/code&gt;, you still need to put empty parentheses at the end of the line to tell Python to actually &lt;a href=&quot;https://realpython.com/videos/example-function/&quot;&gt;execute that function&lt;/a&gt; rather than just refer to it by name. Without parentheses, you’d obtain a &lt;a href=&quot;https://en.wikipedia.org/wiki/Reference_(computer_science)&quot;&gt;reference&lt;/a&gt; to the underlying function object:&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.437b3be14035.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;print&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;nb&quot;&gt;print&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;built-in function print&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The code snippet above runs within an interactive &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python REPL&lt;/a&gt;, as indicated by the prompt (&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;). Because the REPL executes each line of Python code immediately, you see a blank line right after calling &lt;code&gt;print()&lt;/code&gt;. On the other hand, when you skip the trailing parentheses, you get to see a string representation of the &lt;code&gt;print()&lt;/code&gt; function itself.&lt;/p&gt;
&lt;p&gt;As you just saw, calling &lt;code&gt;print()&lt;/code&gt; without arguments results in a blank line, which is a line comprised solely of the newline character. Don’t confuse this with an &lt;strong&gt;empty string&lt;/strong&gt;, which doesn’t contain any characters at all, not even the newline!&lt;/p&gt;
&lt;p&gt;You can use &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;Python’s string&lt;/a&gt; literals to visualize these two:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Blank Line:&lt;/strong&gt; &lt;code&gt;&quot;\n&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Empty String:&lt;/strong&gt; &lt;code&gt;&quot;&quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first string literal is exactly one character long, whereas the second one has no content—it’s empty.&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 remove the newline character from a string in Python, use its &lt;code&gt;.rstrip()&lt;/code&gt; method, like this:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;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.437b3be14035.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A line of text.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rstrip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;A line of text.&#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.437b3be14035.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.437b3be14035.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 strips any trailing whitespace from the right edge of the string of characters. To learn more about &lt;code&gt;.rstrip()&lt;/code&gt;, check out the &lt;a href=&quot;https://realpython.com/python-strip/&quot;&gt;How to Strip Characters From a Python String&lt;/a&gt; tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Even though Python usually takes care of the newline character for you, it helps to understand how to deal with it yourself.&lt;/p&gt;
&lt;h3 id=&quot;dealing-with-newlines&quot;&gt;Dealing With Newlines&lt;a class=&quot;headerlink&quot; href=&quot;#dealing-with-newlines&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-print/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-print/ »&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: The Python print() Function</title>
      <id>https://realpython.com/quizzes/python-print-guide/</id>
      <link href="https://realpython.com/quizzes/python-print-guide/"/>
      <updated>2025-06-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s built-in print() function, covering how to format output, specify custom separators, and more.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;Your Guide to the Python print() Function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;print()&lt;/code&gt; function outputs objects to the console or a specified file-like stream. You&amp;rsquo;ll practice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Printing multiple values with custom separators&lt;/li&gt;
&lt;li&gt;Changing the end-of-line character&lt;/li&gt;
&lt;li&gt;Redirecting output using the &lt;code&gt;file&lt;/code&gt; parameter&lt;/li&gt;
&lt;li&gt;Forcing immediate output with the &lt;code&gt;flush&lt;/code&gt; parameter&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Work through these questions to reinforce your knowledge of &lt;code&gt;print()&lt;/code&gt;&amp;rsquo;s parameters and best practices for clear, formatted I/O.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Starting With DuckDB and Python</title>
      <id>https://realpython.com/courses/starting-duckdb-python/</id>
      <link href="https://realpython.com/courses/starting-duckdb-python/"/>
      <updated>2025-06-24T14:00:00+00:00</updated>
      <summary>Learn how to use DuckDB in Python to query large datasets with SQL or its Python API, handle files like Parquet or CSV, and integrate with pandas or Polars.</summary>
      <content type="html">
        &lt;p&gt;The DuckDB database provides a seamless way to handle large datasets in Python with Online Analytical Processing (OLAP) optimization. You can create databases, verify data imports, and perform efficient data queries using both SQL and DuckDB&amp;rsquo;s Python API.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can &lt;strong&gt;create a DuckDB database&lt;/strong&gt; by reading data from files like Parquet, CSV, or JSON and saving it to a table.&lt;/li&gt;
&lt;li&gt;You &lt;strong&gt;query a DuckDB database&lt;/strong&gt; using standard SQL syntax within Python by executing queries through a DuckDB connection object.&lt;/li&gt;
&lt;li&gt;You can also use &lt;strong&gt;DuckDB&amp;rsquo;s Python API&lt;/strong&gt;, which uses method chaining for an object-oriented approach to database queries.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrent access in DuckDB&lt;/strong&gt; allows multiple reads but restricts concurrent writes to ensure data integrity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DuckDB integrates with pandas and Polars&lt;/strong&gt; by converting query results into DataFrames using the &lt;code&gt;.df()&lt;/code&gt; or &lt;code&gt;.pl()&lt;/code&gt; methods.&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python enumerate(): Simplify Loops That Need Counters</title>
      <id>https://realpython.com/python-enumerate/</id>
      <link href="https://realpython.com/python-enumerate/"/>
      <updated>2025-06-23T14:00:00+00:00</updated>
      <summary>Learn how to simplify your loops with Python’s enumerate(). This tutorial shows you how to pair items with their index cleanly and effectively using real-world examples.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;enumerate()&lt;/code&gt; function helps you with loops that require a counter by adding an index to each item in an iterable. This is particularly useful when you need both the index and value while iterating, such as listing items with their positions. You can also customize the starting index with the &lt;code&gt;start&lt;/code&gt; argument, offering flexibility in various scenarios.&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;enumerate()&lt;/code&gt;&lt;/strong&gt; in Python &lt;strong&gt;adds a counter to an iterable&lt;/strong&gt; and returns it as an &lt;code&gt;enumerate&lt;/code&gt; object, pairing each item with an index.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;enumerate()&lt;/code&gt;&lt;/strong&gt; accepts an iterable and &lt;strong&gt;an optional &lt;code&gt;start&lt;/code&gt; argument&lt;/strong&gt; to set the initial index value.&lt;/li&gt;
&lt;li&gt;The advantage of &lt;strong&gt;&lt;code&gt;enumerate()&lt;/code&gt;&lt;/strong&gt; is that it &lt;strong&gt;provides both index and value pairs&lt;/strong&gt; without manual counter management.&lt;/li&gt;
&lt;li&gt;You can use &lt;strong&gt;&lt;code&gt;zip()&lt;/code&gt; or slicing as alternatives to &lt;code&gt;enumerate()&lt;/code&gt;&lt;/strong&gt; for iterating multiple sequences or selecting specific elements.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Explore how to implement your own version of &lt;code&gt;enumerate()&lt;/code&gt; and discover alternative methods like &lt;code&gt;zip()&lt;/code&gt; and &lt;code&gt;itertools&lt;/code&gt; for more complex iteration patterns.&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-enumerate-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-enumerate-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 explore how enumerate() works in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;using-pythons-enumerate&quot;&gt;Using Python’s &lt;code&gt;enumerate()&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#using-pythons-enumerate&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;There are situations when you need both the index and the value of items in an &lt;a href=&quot;/ref/glossary/iterable/&quot; class=&quot;ref-link&quot;&gt;iterable&lt;/a&gt;. That’s when Python’s &lt;a href=&quot;/ref/builtin-functions/enumerate/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;enumerate()&lt;/code&gt;&lt;/a&gt; function can come in handy for you. &lt;/p&gt;
&lt;p&gt;Python’s &lt;strong&gt;&lt;code&gt;enumerate()&lt;/code&gt;&lt;/strong&gt; function adds a counter to an iterable and returns it in the form of an &lt;code&gt;enumerate&lt;/code&gt; object, which can be used directly in loops. For example, when you want to display the winners of a race, you might write:&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.437b3be14035.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;runners&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Lenka&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Martina&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Gugu&quot;&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;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;winner&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;runners&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;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;winner&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, &#x27;Lenka&#x27;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, &#x27;Martina&#x27;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, &#x27;Gugu&#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.437b3be14035.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.437b3be14035.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 &lt;code&gt;enumerate()&lt;/code&gt; is a &lt;a href=&quot;/ref/builtin-functions/&quot; class=&quot;ref-link&quot;&gt;built-in function&lt;/a&gt;, you can use it right away without importing it. When you use &lt;code&gt;enumerate()&lt;/code&gt; in a &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt;, you get pairs of count and value from the iterable.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’re coming from languages like &lt;a href=&quot;https://realpython.com/c-for-python-programmers/&quot;&gt;C&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/java-vs-python/&quot;&gt;Java&lt;/a&gt;, or &lt;a href=&quot;https://realpython.com/python-vs-javascript/&quot;&gt;JavaScript&lt;/a&gt;, you might be tempted to use &lt;code&gt;range(len())&lt;/code&gt; to get both the index and value in a loop. While this works in Python, &lt;code&gt;enumerate()&lt;/code&gt; is considered a more &lt;a href=&quot;/ref/glossary/pythonic/&quot; class=&quot;ref-link&quot;&gt;Pythonic&lt;/a&gt; and preferred approach.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the example above, you’re storing the position and the runner’s name in a &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt; named &lt;code&gt;winner&lt;/code&gt;, which is a &lt;a href=&quot;/ref/builtin-types/tuple/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;tuple&lt;/code&gt;&lt;/a&gt;. To display the position and the name right away, you can &lt;a href=&quot;https://realpython.com/python-tuple/#packing-and-unpacking-tuples&quot;&gt;unpack the &lt;code&gt;tuple&lt;/code&gt;&lt;/a&gt; when you define the &lt;code&gt;for&lt;/code&gt; loop:&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.437b3be14035.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;runners&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Lenka&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Martina&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Gugu&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;hll&quot;&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;position&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;runners&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&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;position&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&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 Lenka&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1 Martina&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2 Gugu&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.437b3be14035.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.437b3be14035.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;Just like the &lt;code&gt;winner&lt;/code&gt; variable earlier, you can name the unpacked loop variables whatever you want. You use &lt;code&gt;position&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; in this example, but they could just as easily be named &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;value&lt;/code&gt;, or any other valid Python names.&lt;/p&gt;
&lt;div class=&quot;card mb-3&quot; id=&quot;collapse_cardd153eb&quot;&gt;
&lt;div class=&quot;card-header border-0&quot;&gt;
&lt;p class=&quot;m-0&quot;&gt;
    &lt;button class=&quot;btn w-100&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapsed153eb&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapsed153eb&quot; markdown=&quot;1&quot;&gt;&lt;span class=&quot;float-left&quot; markdown=&quot;1&quot;&gt;Unpacking Count and Value With &lt;code&gt;enumerate()&lt;/code&gt;&lt;/span&gt;&lt;span class=&quot;float-right text-muted&quot;&gt;Show/Hide&lt;/span&gt;&lt;/button&gt;
  &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;collapse js-collapsible-section&quot; data-parent=&quot;#collapse_cardd153eb&quot; id=&quot;collapsed153eb&quot;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;p&gt;When you use &lt;code&gt;enumerate()&lt;/code&gt; in a &lt;code&gt;for&lt;/code&gt; loop, you typically tell Python to use two variables: one for the count and one for the value itself. You’re able to do this by applying a Python concept called &lt;a href=&quot;https://realpython.com/python-tuple/#packing-and-unpacking-tuples&quot;&gt;tuple unpacking&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Unpacking is the idea that a tuple—or another type of a &lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;Python sequence&lt;/a&gt;—can be split into several variables depending on the length of that sequence. For instance, you can unpack a tuple of two elements into two variables:&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.437b3be14035.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;cart_item&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Wireless Mouse&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;product_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;quantity_ordered&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cart_item&lt;/span&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;product_name&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;Wireless Mouse&#x27;&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;quantity_ordered&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&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.437b3be14035.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.437b3be14035.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;First, you create a tuple with two elements, &lt;code&gt;&quot;Wireless Mouse&quot;&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt;. Then, you unpack that tuple into &lt;code&gt;product_name&lt;/code&gt; and &lt;code&gt;quantity_ordered&lt;/code&gt;, which are each assigned one of the values from the tuple.&lt;/p&gt;
&lt;p&gt;When you call &lt;code&gt;enumerate()&lt;/code&gt; and pass a sequence of values, Python returns an &lt;a href=&quot;/ref/glossary/iterator/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;iterator&lt;/strong&gt;&lt;/a&gt;. When you ask the iterator for its next value, it yields a tuple with two elements. The first element of the tuple is the count, and the second element is the value from the sequence that you passed:&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.437b3be14035.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;values&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;first&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;second&quot;&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;enumerate_instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&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;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;enumerate at 0x7fe75d728180&amp;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;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(0, &#x27;first&#x27;)&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;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(1, &#x27;second&#x27;)&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;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
  File &lt;span class=&quot;nb&quot;&gt;&quot;&amp;lt;python-input-5&amp;gt;&quot;&lt;/span&gt;, line &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;, in &lt;span class=&quot;n&quot;&gt;&amp;lt;module&amp;gt;&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumerate_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;pm&quot;&gt;~~~~^^^^^^^^^^^^^^^&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;StopIteration&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you create a &lt;a href=&quot;https://realpython.com/python-list/&quot;&gt;Python list&lt;/a&gt; called &lt;code&gt;values&lt;/code&gt; with two elements, &lt;code&gt;&quot;first&quot;&lt;/code&gt; and &lt;code&gt;&quot;second&quot;&lt;/code&gt;. Then, you pass &lt;code&gt;values&lt;/code&gt; to &lt;code&gt;enumerate()&lt;/code&gt; and assign the return value to &lt;code&gt;enumerate_instance&lt;/code&gt;. When you &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;print&lt;/a&gt; &lt;code&gt;enumerate_instance&lt;/code&gt;, you’ll see that it’s an &lt;code&gt;enumerate&lt;/code&gt; object with a particular memory address.&lt;/p&gt;
&lt;p&gt;Then, you use Python’s built-in &lt;a href=&quot;/ref/builtin-functions/next/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;next()&lt;/code&gt;&lt;/a&gt; to get the next value from &lt;code&gt;enumerate_instance&lt;/code&gt;. The first value that &lt;code&gt;enumerate_instance&lt;/code&gt; returns is a tuple with the count &lt;code&gt;0&lt;/code&gt; and the first element from &lt;code&gt;values&lt;/code&gt;, which is &lt;code&gt;&quot;first&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Calling &lt;code&gt;next()&lt;/code&gt; again on &lt;code&gt;enumerate_instance&lt;/code&gt; yields another tuple—this time, with the count &lt;code&gt;1&lt;/code&gt; and the second element from &lt;code&gt;values&lt;/code&gt;, &lt;code&gt;&quot;second&quot;&lt;/code&gt;. Finally, calling &lt;code&gt;next()&lt;/code&gt; one more time raises a &lt;a href=&quot;/ref/builtin-exceptions/stopiteration/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;StopIteration&lt;/code&gt;&lt;/a&gt; exception since there are no more values to be returned from &lt;code&gt;enumerate_instance&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When an iterable is used in a &lt;code&gt;for&lt;/code&gt; loop, Python automatically calls &lt;code&gt;next()&lt;/code&gt; at the start of every iteration until &lt;code&gt;StopIteration&lt;/code&gt; is raised. Python assigns the value it retrieves from the iterable to the loop variable.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;By default, the count of &lt;code&gt;enumerate()&lt;/code&gt; starts at &lt;code&gt;0&lt;/code&gt;. This isn’t ideal when you want to display the winners of a race. Luckily, Python’s &lt;code&gt;enumerate()&lt;/code&gt; has one additional &lt;a href=&quot;/ref/glossary/argument/&quot; class=&quot;ref-link&quot;&gt;argument&lt;/a&gt; that you can use to control the starting value of the count.&lt;/p&gt;
&lt;p&gt;When you call &lt;code&gt;enumerate()&lt;/code&gt;, you can use the &lt;code&gt;start&lt;/code&gt; argument to change the starting count:&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.437b3be14035.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;runners&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Lenka&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Martina&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Gugu&quot;&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;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;runners&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&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;p&quot;&gt;):&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;position&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&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;1 Lenka&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2 Martina&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3 Gugu&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you pass &lt;code&gt;start=1&lt;/code&gt;, which initializes &lt;code&gt;position&lt;/code&gt; with the value &lt;code&gt;1&lt;/code&gt; on the first loop iteration.&lt;/p&gt;
&lt;p&gt;You should use &lt;code&gt;enumerate()&lt;/code&gt; anytime you need to use the count and an item in a loop. Keep in mind that &lt;code&gt;enumerate()&lt;/code&gt; increments the count by one on every iteration. However, this only slightly limits your flexibility. Since the count is a standard &lt;a href=&quot;https://realpython.com/python-data-types/#integer-numbers&quot;&gt;Python integer&lt;/a&gt;, you can use it in many ways.&lt;/p&gt;
&lt;h2 id=&quot;practicing-with-python-enumerate&quot;&gt;Practicing With Python &lt;code&gt;enumerate()&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#practicing-with-python-enumerate&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Now that you’ve explored the basics of &lt;code&gt;enumerate()&lt;/code&gt;, it’s time to practice using &lt;code&gt;enumerate()&lt;/code&gt; with some real-world examples.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-enumerate/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-enumerate/ »&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 #254: Scaling Python Web Applications With Kubernetes and Karpenter</title>
      <id>https://realpython.com/podcasts/rpp/254/</id>
      <link href="https://realpython.com/podcasts/rpp/254/"/>
      <updated>2025-06-20T12:00:00+00:00</updated>
      <summary>What goes into scaling a web application today? What are resources for learning and practicing DevOps skills? This week on the show, Calvin Hendryx-Parker is back to discuss the tools and infrastructure for autoscaling web applications with Kubernetes and Karpenter.</summary>
      <content type="html">
        &lt;p&gt;What goes into scaling a web application today? What are resources for learning and practicing DevOps skills? This week on the show, Calvin Hendryx-Parker is back to discuss the tools and infrastructure for autoscaling web applications with Kubernetes and Karpenter.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Project: Build a Word Count Command-Line App</title>
      <id>https://realpython.com/courses/word-count-app-project/</id>
      <link href="https://realpython.com/courses/word-count-app-project/"/>
      <updated>2025-06-18T14:00:00+00:00</updated>
      <summary>A self-paced coding challenge in which you&#x27;ll practice your Python skills by building a clone of the popular word count utility (wc) on Unix.</summary>
      <content type="html">
        &lt;p&gt;The &lt;strong&gt;word count&lt;/strong&gt; command (&lt;a href=&quot;https://en.wikipedia.org/wiki/Wc_(Unix)&quot;&gt;&lt;code&gt;wc&lt;/code&gt;&lt;/a&gt;) is a classic utility that you might use to determine the number of lines, words, and bytes in files or &lt;a href=&quot;https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)&quot;&gt;standard input&lt;/a&gt;. It&amp;rsquo;s a staple tool for anyone working with text files on &lt;a href=&quot;https://en.wikipedia.org/wiki/Unix-like&quot;&gt;Unix-like&lt;/a&gt; systems. But have you ever wondered how such a tool is designed and implemented?&lt;/p&gt;
&lt;p&gt;In this practice exercise, you&amp;rsquo;ll dive into the inner workings of the Unix &lt;code&gt;wc&lt;/code&gt; command by building its simplified version from scratch using Python. Not only will this coding challenge solidify your understanding of &lt;a href=&quot;https://realpython.com/working-with-files-in-python/&quot;&gt;file handling&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-string-split-concatenate-join/&quot;&gt;text processing&lt;/a&gt;, but it&amp;rsquo;ll also give you a taste of how to structure &lt;a href=&quot;https://realpython.com/python-command-line-arguments/&quot;&gt;command-line utilities&lt;/a&gt; in Python.&lt;/p&gt;
&lt;p&gt;By the end of this challenge, you&amp;rsquo;ll have a functional version of the &lt;code&gt;wc&lt;/code&gt; command that can faithfully reproduce the outputs you&amp;rsquo;re accustomed to seeing in a Unix &lt;a href=&quot;https://realpython.com/terminal-commands/&quot;&gt;terminal&lt;/a&gt;. However, it won&amp;rsquo;t be an exact replica of the &lt;code&gt;wc&lt;/code&gt; command, as you&amp;rsquo;ll omit or adapt some features for simplicity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this coding challenge, you&amp;rsquo;ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read content from &lt;strong&gt;files&lt;/strong&gt; and &lt;strong&gt;standard input (stdin)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Count the number of &lt;strong&gt;lines&lt;/strong&gt;, &lt;strong&gt;words&lt;/strong&gt;, and &lt;strong&gt;bytes&lt;/strong&gt; in the input&lt;/li&gt;
&lt;li&gt;Differentiate between bytes and &lt;strong&gt;characters&lt;/strong&gt; to handle &lt;strong&gt;Unicode&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Implement &lt;strong&gt;command-line arguments&lt;/strong&gt; to specify what counts to display&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While working on this challenge, you&amp;rsquo;ll gain hands-on experience with several modules from Python&amp;rsquo;s standard library, such as &lt;a href=&quot;https://realpython.com/python-pathlib/&quot;&gt;&lt;code&gt;pathlib&lt;/code&gt;&lt;/a&gt; for manipulating the file system and &lt;a href=&quot;https://realpython.com/command-line-interfaces-python-argparse/&quot;&gt;&lt;code&gt;argparse&lt;/code&gt;&lt;/a&gt; for parsing command-line arguments. Familiarity with basic Python programming and file handling will be beneficial, but detailed instructions and helpful tips will guide you through each step of the process.&lt;/p&gt;
&lt;p&gt;The challenge is broken down into a number of &lt;strong&gt;tasks&lt;/strong&gt;, each accompanied by clear instructions and illustrative examples. You&amp;rsquo;ll receive &lt;strong&gt;automated feedback&lt;/strong&gt; on your solutions when you follow along using the accompanying materials. If you run into any issues or have questions, then don&amp;rsquo;t hesitate to ask for help in the &lt;strong&gt;comments section&lt;/strong&gt; below the corresponding lesson.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can also reach out to the Real Python community on &lt;a href=&quot;https://realpython.com/community/&quot;&gt;Slack&lt;/a&gt; or join live conversations during &lt;a href=&quot;https://realpython.com/office-hours/&quot;&gt;Office Hours&lt;/a&gt;, where you&amp;rsquo;ll have an opportunity to share your screen remotely.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Completing each task unlocks the next one. Once you&amp;rsquo;ve completed a task, you can compare your code with the &lt;strong&gt;sample solution&lt;/strong&gt; provided in the following lesson. Remember that there&amp;rsquo;s often more than one way to solve a problem. If your solution differs slightly but meets the acceptance criteria and adheres to good programming practices, then that&amp;rsquo;s perfectly fine.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Exploring Python&#x27;s list Data Type With Examples</title>
      <id>https://realpython.com/courses/list-data-type-with-examples/</id>
      <link href="https://realpython.com/courses/list-data-type-with-examples/"/>
      <updated>2025-06-17T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll dive deep into Python&#x27;s lists: how to create them, update their content, populate and grow them - with practical code examples.</summary>
      <content type="html">
        &lt;p&gt;The &lt;strong&gt;&lt;code&gt;list&lt;/code&gt;&lt;/strong&gt; class is a fundamental &lt;strong&gt;built-in data type&lt;/strong&gt; in Python. It has an impressive and useful set of features, allowing you to efficiently organize and manipulate heterogeneous data. Knowing how to use lists is a must-have skill for you as a Python developer. Lists have many use cases, so you&amp;rsquo;ll frequently reach for them in real-world coding.&lt;/p&gt;
&lt;p&gt;By working through this video course, you&amp;rsquo;ll dive deep into lists and get a solid understanding of their key features. This knowledge will allow you to write more effective code by taking advantage of lists.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Create&lt;/strong&gt; new lists in Python&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access&lt;/strong&gt; the items in an existing list&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Copy&lt;/strong&gt;, &lt;strong&gt;update&lt;/strong&gt;, &lt;strong&gt;grow&lt;/strong&gt;, &lt;strong&gt;shrink&lt;/strong&gt;, and &lt;strong&gt;concatenate&lt;/strong&gt; existing lists&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sort&lt;/strong&gt;, &lt;strong&gt;reverse&lt;/strong&gt;, and &lt;strong&gt;traverse&lt;/strong&gt; existing lists&lt;/li&gt;
&lt;li&gt;Use other &lt;strong&gt;features&lt;/strong&gt; of Python lists&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Write Pythonic and Clean Code With namedtuple</title>
      <id>https://realpython.com/python-namedtuple/</id>
      <link href="https://realpython.com/python-namedtuple/"/>
      <updated>2025-06-16T14:00:00+00:00</updated>
      <summary>Discover how Python&#x27;s namedtuple lets you create simple, readable data structures with named fields you can access using dot notation.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s &lt;code&gt;namedtuple&lt;/code&gt; in the &lt;code&gt;collections&lt;/code&gt; module allows you to create immutable sequences with named fields, providing a more readable and Pythonic way to handle tuples. You use &lt;code&gt;namedtuple&lt;/code&gt; to access values with descriptive field names and dot notation, which improves code clarity and maintainability.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Python’s &lt;strong&gt;&lt;code&gt;namedtuple&lt;/code&gt;&lt;/strong&gt; is a &lt;strong&gt;factory function&lt;/strong&gt; that creates tuple subclasses with named fields.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;main difference&lt;/strong&gt; between &lt;code&gt;tuple&lt;/code&gt; and &lt;code&gt;namedtuple&lt;/code&gt; is that &lt;code&gt;namedtuple&lt;/code&gt; allows attribute access via &lt;strong&gt;named fields&lt;/strong&gt;, enhancing readability.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;point of using &lt;code&gt;namedtuple&lt;/code&gt;&lt;/strong&gt; is to improve code clarity by allowing access to elements through descriptive names instead of integer indices.&lt;/li&gt;
&lt;li&gt;Some &lt;strong&gt;alternatives&lt;/strong&gt; to &lt;code&gt;namedtuple&lt;/code&gt; include dictionaries, data classes, and &lt;code&gt;typing.NamedTuple&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Dive deeper into creating &lt;code&gt;namedtuple&lt;/code&gt; classes, exploring their powerful features, and writing Python code that’s easier to read and maintain.&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-namedtuple-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-namedtuple-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 namedtuple to write Pythonic and clean code.&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.437b3be14035.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 “Write Pythonic and Clean Code With namedtuple” 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-namedtuple/&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;Write Pythonic and Clean Code With namedtuple&quot; src=&quot;https://files.realpython.com/media/Clean-Up-Your-Python-Code-With-namedtuple_Watermarked.0ab0ddbda383.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Clean-Up-Your-Python-Code-With-namedtuple_Watermarked.0ab0ddbda383.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Clean-Up-Your-Python-Code-With-namedtuple_Watermarked.0ab0ddbda383.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Clean-Up-Your-Python-Code-With-namedtuple_Watermarked.0ab0ddbda383.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Clean-Up-Your-Python-Code-With-namedtuple_Watermarked.0ab0ddbda383.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.437b3be14035.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-namedtuple/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Write Pythonic and Clean Code With namedtuple&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 namedtuple() factory function from the collections module.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-namedtuple-in-python&quot;&gt;Getting to Know &lt;code&gt;namedtuple&lt;/code&gt; in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-namedtuple-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python’s &lt;a href=&quot;https://docs.python.org/3/library/collections.html#collections.namedtuple&quot;&gt;&lt;code&gt;namedtuple()&lt;/code&gt;&lt;/a&gt; is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Factory_(object-oriented_programming)&quot;&gt;factory function&lt;/a&gt; that’s available in the &lt;a href=&quot;https://docs.python.org/3/library/collections.html#module-collections&quot;&gt;&lt;code&gt;collections&lt;/code&gt;&lt;/a&gt; module. It allows you to create a &lt;a href=&quot;https://realpython.com/python-tuple/&quot;&gt;&lt;code&gt;tuple&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;/ref/glossary/subclass/&quot; class=&quot;ref-link&quot;&gt;subclass&lt;/a&gt; with &lt;strong&gt;named fields&lt;/strong&gt;. These named fields let you to access the values in a given named tuple using &lt;a href=&quot;/ref/glossary/dot-notation/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;dot notation&lt;/strong&gt;&lt;/a&gt; and field names—for example, &lt;code&gt;my_tuple.field_name&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Python’s &lt;code&gt;namedtuple&lt;/code&gt; was created to improve code readability by providing a way to access values using descriptive field names instead of integer indices, which often don’t provide any context on what the values are. This feature also makes the code cleaner and more maintainable.&lt;/p&gt;
&lt;p&gt;In contrast, accessing values by index in a regular tuple can be frustrating, hard to read, and error-prone. This is especially true if the tuple has a lot of fields and is constructed far away from where you’re using it.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In this tutorial, you’ll find different terms used to refer to Python’s &lt;code&gt;namedtuple&lt;/code&gt;, its factory function, and its instances.&lt;/p&gt;
&lt;p&gt;To avoid confusion, here’s a summary of how each term is used throughout the tutorial:&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;Term&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;namedtuple()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The factory function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;namedtuple&lt;/code&gt;, &lt;code&gt;namedtuple&lt;/code&gt; class&lt;/td&gt;
&lt;td&gt;The tuple subclass returned by &lt;code&gt;namedtuple()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;namedtuple&lt;/code&gt; instance, named tuple&lt;/td&gt;
&lt;td&gt;An instance of a specific &lt;code&gt;namedtuple&lt;/code&gt; class&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;You’ll find these terms used with their corresponding meaning throughout the tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Besides providing named fields, named tuples in Python offer the following features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Are &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/&quot;&gt;immutable&lt;/a&gt; data structures&lt;/li&gt;
&lt;li&gt;Can have a &lt;a href=&quot;https://docs.python.org/3/library/functions.html#hash&quot;&gt;hash&lt;/a&gt; value and work as &lt;strong&gt;dictionary keys&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Can be stored in &lt;a href=&quot;https://realpython.com/python-sets/&quot;&gt;sets&lt;/a&gt; when they have a hash value&lt;/li&gt;
&lt;li&gt;Generate a basic &lt;a href=&quot;https://realpython.com/documenting-python-code/&quot;&gt;docstring&lt;/a&gt; using the type and field names&lt;/li&gt;
&lt;li&gt;Provide a helpful &lt;a href=&quot;/ref/glossary/string-representation/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;string representation&lt;/strong&gt;&lt;/a&gt; that displays the tuple content in a &lt;code&gt;name=value&lt;/code&gt; format&lt;/li&gt;
&lt;li&gt;Support &lt;a href=&quot;/ref/glossary/indexing/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;indexing&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;/ref/glossary/slicing/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;slicing&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Provide additional &lt;a href=&quot;/ref/glossary/method/&quot; class=&quot;ref-link&quot;&gt;methods&lt;/a&gt; and &lt;a href=&quot;/ref/glossary/attribute/&quot; class=&quot;ref-link&quot;&gt;attributes&lt;/a&gt;, such as &lt;a href=&quot;https://docs.python.org/3/library/collections.html#collections.somenamedtuple._make&quot;&gt;&lt;code&gt;._make()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://docs.python.org/3/library/collections.html#collections.somenamedtuple._asdict&quot;&gt;&lt;code&gt;_asdict()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&quot;https://docs.python.org/3/library/collections.html#collections.somenamedtuple._fields&quot;&gt;&lt;code&gt;._fields&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Are &lt;strong&gt;backward compatible&lt;/strong&gt; with regular tuples&lt;/li&gt;
&lt;li&gt;Have &lt;strong&gt;similar memory usage&lt;/strong&gt; to regular tuples&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can use &lt;code&gt;namedtuple&lt;/code&gt; instances wherever you need a tuple-like object. They offer the added benefit of accessing values using field names and dot notation, which makes your code more readable and Pythonic.&lt;/p&gt;
&lt;p&gt;With this brief introduction to &lt;code&gt;namedtuple&lt;/code&gt; and its general features, you’re ready to explore how to create and use them effectively in your own code.&lt;/p&gt;
&lt;h2 id=&quot;creating-tuple-like-classes-with-the-namedtuple-function&quot;&gt;Creating Tuple-Like Classes With the &lt;code&gt;namedtuple()&lt;/code&gt; Function&lt;a class=&quot;headerlink&quot; href=&quot;#creating-tuple-like-classes-with-the-namedtuple-function&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You use a &lt;code&gt;namedtuple()&lt;/code&gt; to create an &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-immutable&quot;&gt;immutable&lt;/a&gt;, tuple-like &lt;a href=&quot;/ref/glossary/sequence/&quot; class=&quot;ref-link&quot;&gt;sequence&lt;/a&gt; with named fields. A popular example that you’ll often find in resources about &lt;code&gt;namedtuple&lt;/code&gt; is defining a class to represent a mathematical &lt;a href=&quot;https://en.wikipedia.org/wiki/Point_(geometry)&quot;&gt;point&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Depending on the problem, you’ll probably want to use an immutable data structure to represent your points. Here’s how you can create a two-dimensional point using a regular tuple:&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.437b3be14035.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;c1&quot;&gt;# Create a 2D point as a regular tuple&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;point&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;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&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;point&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;(2, 4)&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Access coordinate x&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;point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Access coordinate y&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;point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Try to update a coordinate value&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;point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;TypeError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;&#x27;tuple&#x27; object does not support item assignment&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you create an immutable, two-dimensional &lt;code&gt;point&lt;/code&gt; using a regular tuple. This code works. You have a &lt;code&gt;point&lt;/code&gt; with two coordinates that you can access by index. The point is immutable, so you can’t modify the coordinates. However, do you think this code is readable? Can you tell upfront what the &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt; indices mean?&lt;/p&gt;
&lt;p&gt;To improve clarity, you can use a &lt;code&gt;namedtuple&lt;/code&gt; like in the following code. Note that you need to import the function from the &lt;code&gt;collections&lt;/code&gt; module first:&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.437b3be14035.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;collections&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;namedtuple&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Create a namedtuple type, Point&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;Point&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;namedtuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Point&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;x y&quot;&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;point&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&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;point&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Point(x=2, y=4)&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Access the coordinates by field name&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;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Access the coordinates by index&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;point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;AttributeError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;can&#x27;t set attribute&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;issubclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;tuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;True&lt;/span&gt;
&lt;/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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now you have a &lt;code&gt;Point&lt;/code&gt; class with two appropriately named fields, &lt;code&gt;.x&lt;/code&gt; and &lt;code&gt;.y&lt;/code&gt;. Your &lt;code&gt;point&lt;/code&gt; provides a descriptive string representation by default: &lt;code&gt;Point(x=2, y=4)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can access the coordinates with dot notation and the field names, which is convenient, readable, and explicit. You can also use indices to access each coordinate’s value if you prefer.&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; As with regular tuples, named tuples are &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/&quot;&gt;immutable&lt;/a&gt;. However, the values they store don’t necessarily have to be immutable.&lt;/p&gt;
&lt;p&gt;It’s completely valid to create a tuple or a named tuple that holds mutable values:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.437b3be14035.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;collections&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;namedtuple&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;Person&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;namedtuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Person&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;name children&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;john&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;John Doe&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;span class=&quot;s2&quot;&gt;&quot;Timmy&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Jimmy&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&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;john&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Person(name=&#x27;John Doe&#x27;, children=[&#x27;Timmy&#x27;, &#x27;Jimmy&#x27;])&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;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;john&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;139695902374144&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;john&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Tina&quot;&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;john&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Person(name=&#x27;John Doe&#x27;, children=[&#x27;Timmy&#x27;, &#x27;Jimmy&#x27;, &#x27;Tina&#x27;])&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;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;john&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;139695902374144&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;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;john&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;TypeError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;unhashable type: &#x27;list&#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.437b3be14035.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.437b3be14035.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 create named tuples that contain mutable objects. Then, you can modify the mutable objects in the underlying tuple. However, this doesn’t mean that you’re modifying the tuple itself. The tuple will continue being the same object.&lt;/p&gt;
&lt;p&gt;Finally, tuples or named tuples with mutable values aren’t &lt;a href=&quot;/ref/glossary/hashable/&quot; class=&quot;ref-link&quot;&gt;hashable&lt;/a&gt;, as you saw in the above example.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-namedtuple/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-namedtuple/ »&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 #253: Starting With marimo Notebooks &amp; Python App Config Management</title>
      <id>https://realpython.com/podcasts/rpp/253/</id>
      <link href="https://realpython.com/podcasts/rpp/253/"/>
      <updated>2025-06-13T12:00:00+00:00</updated>
      <summary>Looking for a guide on getting started with marimo notebooks? How do you build a reproducible notebook for sharing or create a dashboard with interactive UI elements? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;Looking for a guide on getting started with marimo notebooks? How do you build a reproducible notebook for sharing or create a dashboard with interactive UI elements? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Defining Your Own Python Function</title>
      <id>https://realpython.com/defining-your-own-python-function/</id>
      <link href="https://realpython.com/defining-your-own-python-function/"/>
      <updated>2025-06-11T14:00:00+00:00</updated>
      <summary>Learn how to define your own Python function, pass data into it, and return results to write clean, reusable code in your programs.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;A Python function is a named block of code that performs specific tasks and can be reused in other parts of your code. Python has several built-in functions that are always available, and you can also create your own. These are known as user-defined functions.&lt;/p&gt;
&lt;p&gt;To define a function in Python, you use the &lt;code&gt;def&lt;/code&gt; keyword, followed by the function name and an optional list of parameters enclosed in a required pair of parentheses. You can call and reuse a function by using its name, a pair of parentheses, and the necessary arguments.&lt;/p&gt;
&lt;p&gt;Learning to define and call functions is a fundamental skill for any Python developer. Functions help organize your code and make it more modular, reusable, and easier to maintain.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Python function&lt;/strong&gt; is a &lt;strong&gt;self-contained block&lt;/strong&gt; of code designed to perform a &lt;strong&gt;specific task&lt;/strong&gt;, which you can call and &lt;strong&gt;reuse&lt;/strong&gt; in different parts of your code.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;define&lt;/strong&gt; a Python function with the &lt;strong&gt;&lt;code&gt;def&lt;/code&gt; keyword&lt;/strong&gt;, followed by the &lt;strong&gt;function name&lt;/strong&gt;, &lt;strong&gt;parentheses&lt;/strong&gt; with &lt;strong&gt;optional parameters&lt;/strong&gt;, a colon, and then an &lt;strong&gt;indented code block&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You &lt;strong&gt;call&lt;/strong&gt; a Python function by writing its &lt;strong&gt;name&lt;/strong&gt; followed by &lt;strong&gt;parentheses&lt;/strong&gt;, enclosing any necessary &lt;strong&gt;arguments&lt;/strong&gt;, to execute its code block.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding functions is key to writing organized and efficient Python code. By learning to define and use your own functions, you’ll be able to manage complexity and make your code easier to read.&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/defining-your-own-python-function-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-defining-your-own-python-function-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 define your own function 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.437b3be14035.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 “Defining Your Own Python Function” 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-function/&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;Defining Your Own Python Function&quot; src=&quot;https://files.realpython.com/media/UPDATE-Defining-Your-Own-Python-Function_Watermarked.54412dcabb8d.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-Defining-Your-Own-Python-Function_Watermarked.54412dcabb8d.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/UPDATE-Defining-Your-Own-Python-Function_Watermarked.54412dcabb8d.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/UPDATE-Defining-Your-Own-Python-Function_Watermarked.54412dcabb8d.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/UPDATE-Defining-Your-Own-Python-Function_Watermarked.54412dcabb8d.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.437b3be14035.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-function/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Defining Your Own Python Function&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 defining and calling Python functions. You&#x27;ll revisit the def keyword, parameters, arguments, and more.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-functions-in-python&quot;&gt;Getting to Know Functions in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-functions-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In mathematics, a &lt;strong&gt;function&lt;/strong&gt; is a relationship or mapping between one or more inputs and a set of outputs. This concept is typically represented by the following equation:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/math-function.8bb35bb0fd7e.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/math-function.8bb35bb0fd7e.png&quot; width=&quot;384&quot; height=&quot;83&quot; srcset=&quot;/cdn-cgi/image/width=96,format=auto/https://files.realpython.com/media/math-function.8bb35bb0fd7e.png 96w, /cdn-cgi/image/width=128,format=auto/https://files.realpython.com/media/math-function.8bb35bb0fd7e.png 128w, /cdn-cgi/image/width=192,format=auto/https://files.realpython.com/media/math-function.8bb35bb0fd7e.png 192w, /cdn-cgi/image/width=384,format=auto/https://files.realpython.com/media/math-function.8bb35bb0fd7e.png 384w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Math Function&quot; data-asset=&quot;6368&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;Here, &lt;em&gt;f()&lt;/em&gt; is a function that operates on the variables &lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt;, and it generates a result that’s assigned to &lt;em&gt;z&lt;/em&gt;. You can read this formula as &lt;em&gt;z&lt;/em&gt; is a function of &lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt;. But how does this work in practice? As an example, say that you have a concrete function that looks something like the following:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/add-function.38115f478105.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/add-function.38115f478105.png&quot; width=&quot;340&quot; height=&quot;66&quot; srcset=&quot;/cdn-cgi/image/width=85,format=auto/https://files.realpython.com/media/add-function.38115f478105.png 85w, /cdn-cgi/image/width=113,format=auto/https://files.realpython.com/media/add-function.38115f478105.png 113w, /cdn-cgi/image/width=170,format=auto/https://files.realpython.com/media/add-function.38115f478105.png 170w, /cdn-cgi/image/width=340,format=auto/https://files.realpython.com/media/add-function.38115f478105.png 340w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Add Function&quot; data-asset=&quot;6369&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;Now, say that &lt;em&gt;x&lt;/em&gt; is equal to 4 and &lt;em&gt;y&lt;/em&gt; is 2. You can find the value of &lt;em&gt;z&lt;/em&gt; by &lt;em&gt;evaluating&lt;/em&gt; the function. In other words, you add 4 + 2 to get 6 as a result. That’s it!&lt;/p&gt;
&lt;p&gt;Functions are also used in programming. In fact, functions are so fundamental to software development that virtually all modern, mainstream programming languages support them. In programming, a &lt;a href=&quot;/ref/glossary/function/&quot; class=&quot;ref-link&quot;&gt;function&lt;/a&gt; is a self-contained block of code that encapsulates a specific task under a descriptive name that you can reuse in different places of your code.&lt;/p&gt;
&lt;p&gt;Many programming languages have built-in functions, and Python is no exception. For example, Python’s built-in &lt;a href=&quot;https://realpython.com/python-built-in-functions/#knowing-an-objects-identity-id&quot;&gt;&lt;code&gt;id()&lt;/code&gt;&lt;/a&gt; function takes an object as an argument and returns its unique identifier:&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.437b3be14035.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;language&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Python&quot;&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;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;4390667816&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.437b3be14035.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.437b3be14035.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 integer number in this output uniquely identifies the string object you’ve used as an argument. In &lt;a href=&quot;https://realpython.com/cpython-source-code-guide/&quot;&gt;CPython&lt;/a&gt;, this number represents the memory address where the object is stored.&lt;/p&gt;
&lt;p&gt;Note how similar this notation is to what you find in mathematics. In this example, &lt;code&gt;language&lt;/code&gt; is equivalent to &lt;em&gt;x&lt;/em&gt; or &lt;em&gt;y&lt;/em&gt;, and the pair of parentheses &lt;em&gt;calls&lt;/em&gt; the function to run its code, comparable to evaluating a math function. You’ll learn more about &lt;a href=&quot;#calling-functions-in-python&quot;&gt;calling Python functions&lt;/a&gt; in a moment.&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 built-in functions, check out &lt;a href=&quot;https://realpython.com/python-built-in-functions/&quot;&gt;Python’s Built-in Functions: A Complete Exploration&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, the built-in &lt;a href=&quot;https://realpython.com/len-python-function/&quot;&gt;&lt;code&gt;len()&lt;/code&gt;&lt;/a&gt; function takes a data collection as an argument and returns its length:&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.437b3be14035.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;numbers&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;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&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;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&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;items&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;10&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, the list of numbers has ten values, so &lt;code&gt;len()&lt;/code&gt; returns &lt;code&gt;10&lt;/code&gt;. You &lt;a href=&quot;https://realpython.com/python-assignment-operator/&quot;&gt;assign&lt;/a&gt; this value to the &lt;code&gt;items&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt;, which is equivalent to &lt;em&gt;z&lt;/em&gt; in the mathematical equation you saw before.&lt;/p&gt;
&lt;p&gt;Most programming languages—including Python—allow you to define your own functions. When you define a Python function, you decide whether it takes arguments. You’re also responsible for how the function internally computes its result.&lt;/p&gt;
&lt;p&gt;Once you’ve defined a function, you can call it from different parts of your code to execute its specific computation or action. When the function finishes running, it returns to the location where you called it.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/defining-your-own-python-function/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/defining-your-own-python-function/ »&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: Defining Your Own Python Function</title>
      <id>https://realpython.com/quizzes/python-function/</id>
      <link href="https://realpython.com/quizzes/python-function/"/>
      <updated>2025-06-11T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of defining and calling Python functions. You&#x27;ll revisit the def keyword, parameters, arguments, and more.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;Defining Your Own Python Function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll revisit how to define a function with the &lt;code&gt;def&lt;/code&gt; keyword, specify parameters, pass arguments, and call your functions to make code modular and reusable. You&amp;rsquo;ll also see how functions help organize and maintain your Python projects.&lt;/p&gt;
&lt;p&gt;Ready to demonstrate your skills? Let&amp;rsquo;s begin!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Continuous Integration and Deployment Using GitHub Actions</title>
      <id>https://realpython.com/courses/cicd-github-actions/</id>
      <link href="https://realpython.com/courses/cicd-github-actions/"/>
      <updated>2025-06-10T14:00:00+00:00</updated>
      <summary>Agile methodologies rely on robust DevOps systems to manage and automate common tasks in a continually changing codebase. GitHub Actions can help.</summary>
      <content type="html">
        &lt;p&gt;Creating software is an achievement worth celebrating. But software is never static. Bugs need to be fixed, features need to be added, and security demands regular updates. In today&amp;rsquo;s landscape, with agile methodologies dominating, robust &lt;a href=&quot;https://realpython.com/learning-paths/python-devops/&quot;&gt;DevOps&lt;/a&gt; systems are crucial for managing an evolving codebase. That&amp;rsquo;s where GitHub Actions shine, empowering Python developers to automate workflows and ensure their projects adapt seamlessly to change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub Actions&lt;/strong&gt; for Python empowers developers to automate workflows efficiently. This enables teams to maintain software quality while adapting to constant change.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Continuous Integration and Continuous Deployment (CI/CD)&lt;/strong&gt; systems help produce well-tested, high-quality software and streamline deployment. GitHub Actions makes CI/CD accessible to all, allowing automation and customization of workflows directly in your repository. This free service enables developers to execute their software development processes efficiently, improving productivity and code reliability.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;GitHub Actions&lt;/strong&gt; and &lt;strong&gt;workflows&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Automate &lt;strong&gt;linting, testing, and deployment&lt;/strong&gt; of a Python project&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Secure credentials&lt;/strong&gt; used for automation&lt;/li&gt;
&lt;li&gt;Automate &lt;strong&gt;security and dependency updates&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Hits the Big Screen and Other Python News for June 2025</title>
      <id>https://realpython.com/python-news-june-2025/</id>
      <link href="https://realpython.com/python-news-june-2025/"/>
      <updated>2025-06-09T14:00:00+00:00</updated>
      <summary>Python documentary trailer debuts, Python 3.14 enters beta with key PEPs, and the community celebrates new leadership, events, and tools.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;A newly announced documentary brings Python’s history and culture to the screen, offering a rare behind-the-scenes look at the people and philosophies that shaped it. Meanwhile, new releases and PEPs continue to drive the evolution in packaging and language design.&lt;/p&gt;
&lt;p&gt;Conferences also continue to foster inclusion, learning, and connection. With new leadership at the PSF and a slate of impactful updates, the Python community is clearly energized and looking ahead.&lt;/p&gt;
&lt;p&gt;Let’s dive into the biggest developments shaping Python this month.&lt;/p&gt;
&lt;h2 id=&quot;python-documentary-trailer-released&quot;&gt;Python Documentary Trailer Released&lt;a class=&quot;headerlink&quot; href=&quot;#python-documentary-trailer-released&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/channel/UCsUalyRg43M8D60mtHe6YcA&quot;&gt;CultRepo&lt;/a&gt;, formerly known as Honeypot, has unveiled the trailer for its upcoming feature-length documentary &lt;a href=&quot;https://www.youtube.com/watch?v=pqBqdNIPrbo&quot;&gt;&lt;em&gt;Python: The Documentary&lt;/em&gt;&lt;/a&gt;, set to premiere on YouTube later this year. Known for high-quality open-source origin stories like those of &lt;a href=&quot;https://youtu.be/OrxmtDw4pVI?si=6dn5qEraWTqWBq27&quot;&gt;Vue.js&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/8pDqJVdNa44?si=pZRWiAY1tE7JKogG&quot;&gt;React&lt;/a&gt;, and &lt;a href=&quot;https://youtu.be/LB8KwiiUGy0?si=rweXJtAuocPHe9SY&quot;&gt;Node.js&lt;/a&gt;, CultRepo is returning to form with a long-awaited tribute to our beloved programming language.&lt;/p&gt;
&lt;p&gt;The documentary promises a deep dive into Python’s cultural and technical journey, featuring interviews with key contributors including &lt;a href=&quot;https://gvanrossum.github.io/&quot;&gt;Guido van Rossum&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/interview-mariatta-wijaya/&quot;&gt;Mariatta Wijaya&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/podcasts/rpp/249/&quot;&gt;Brett Cannon&lt;/a&gt;, and many others who’ve shaped Python’s legacy.&lt;/p&gt;
&lt;p&gt;The trailer generated &lt;a href=&quot;https://www.linkedin.com/feed/update/urn:li:activity:7330147800946552833/&quot;&gt;buzz across social media&lt;/a&gt; and the Python community after debuting at PyCon US. In the first 15 hours alone, it racked up over 35,000 YouTube views.&lt;/p&gt;
&lt;h2 id=&quot;python-3140-beta-feature-freeze-begins&quot;&gt;Python 3.14.0 Beta Feature Freeze Begins&lt;a class=&quot;headerlink&quot; href=&quot;#python-3140-beta-feature-freeze-begins&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;After a busy alpha cycle, Python 3.14 has entered beta with the release of versions &lt;a href=&quot;https://www.python.org/downloads/release/python-3140b1/&quot;&gt;3.14.0b1&lt;/a&gt; and &lt;a href=&quot;https://www.python.org/downloads/release/python-3140b2/&quot;&gt;3.14.0b2&lt;/a&gt;. This milestone marks the &lt;strong&gt;feature freeze&lt;/strong&gt;, shifting the development focus to bug fixes, polish, and documentation ahead of the final release in October 2025.&lt;/p&gt;
&lt;p&gt;Python 3.14 is shaping up to be a feature-packed release. Highlights include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Template strings&lt;/strong&gt; for safer string processing, allowing expressions like &lt;code&gt;t&quot;Hello {name}&quot;&lt;/code&gt; to capture string components and interpolated values as structured data before formatting. This allows for custom processing and helps prevent injection attacks in templating scenarios.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deferred annotations&lt;/strong&gt; as the new default, meaning type hints are stored as strings rather than evaluated immediately. This reduces import overhead and allows forward references without using quotes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sigstore&lt;/strong&gt; replacing PGP for release verification, offering a modern, keyless signing approach that leverages certificate transparency and removes the complexity of key management that has long hindered PGP adoption.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Enhanced JIT compiler&lt;/strong&gt; with continued improvements to the &lt;a href=&quot;https://realpython.com/python313-free-threading-jit/#jit-compiles-python-to-machine-code&quot;&gt;copy-and-patch&lt;/a&gt; technique introduced in Python 3.13, providing performance changes ranging from 10% slower to 20% faster depending on workload.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Safe external debugger interface&lt;/strong&gt; enabling &lt;code&gt;pdb&lt;/code&gt; to attach to running Python processes by process ID, allowing real-time debugging of live applications without stopping or restarting them.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The timeline remains on track for the final release in October 2025, with additional beta releases expected throughout the summer. Users can expect improved startup performance, better type checking capabilities, and enhanced security verification processes.&lt;/p&gt;
&lt;p&gt;You can preview the upcoming changes by &lt;a href=&quot;https://realpython.com/python-pre-release/&quot;&gt;installing the beta release&lt;/a&gt; in an isolated environment, and help improve Python 3.14 by reporting bugs or compatibility issues.&lt;/p&gt;
&lt;h2 id=&quot;three-accepted-peps-tackle-typing-installation-and-compression&quot;&gt;Three Accepted PEPs Tackle Typing, Installation, and Compression&lt;a class=&quot;headerlink&quot; href=&quot;#three-accepted-peps-tackle-typing-installation-and-compression&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/python-news-june-2025/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-june-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 #252: Rodrigo Girão Serrão: Python Training, itertools, and Idioms</title>
      <id>https://realpython.com/podcasts/rpp/252/</id>
      <link href="https://realpython.com/podcasts/rpp/252/"/>
      <updated>2025-06-06T12:00:00+00:00</updated>
      <summary>Once you&#x27;ve learned the vocabulary and syntax of the Python language, how do you progress into learning the right combinations to put into your code? How can Python&#x27;s built-in itertools library enhance your skills? This week on the show, we speak with Rodrigo Girão Serrão about teaching Python through his blog and his passion for the itertools library.</summary>
      <content type="html">
        &lt;p&gt;Once you&#x27;ve learned the vocabulary and syntax of the Python language, how do you progress into learning the right combinations to put into your code? How can Python&#x27;s built-in itertools library enhance your skills? This week on the show, we speak with Rodrigo Girão Serrão about teaching Python through his blog and his passion for the itertools library.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>How to Find an Absolute Value in Python</title>
      <id>https://realpython.com/python-absolute-value/</id>
      <link href="https://realpython.com/python-absolute-value/"/>
      <updated>2025-06-04T14:00:00+00:00</updated>
      <summary>Learn how to calculate the Python absolute value with abs(), implement the math behind it from scratch, and customize it in your own classes.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Learn how to work with absolute values in Python using the built-in &lt;code&gt;abs()&lt;/code&gt; function for numbers, arrays, and custom objects. This tutorial shows you how to implement the absolute value function from scratch, use &lt;code&gt;abs()&lt;/code&gt; with numbers, and customize its behavior for data types like NumPy arrays and pandas Series.&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 implement the absolute value function in Python using &lt;strong&gt;conditional statements&lt;/strong&gt; or &lt;strong&gt;mathematical operations&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Python’s &lt;strong&gt;built-in &lt;code&gt;abs()&lt;/code&gt; function&lt;/strong&gt; efficiently handles integers, floating-point numbers, complex numbers, and more.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NumPy&lt;/strong&gt; and &lt;strong&gt;pandas&lt;/strong&gt; extend the &lt;code&gt;abs()&lt;/code&gt; function to work directly with &lt;strong&gt;arrays&lt;/strong&gt; and &lt;strong&gt;Series&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can customize the behavior of &lt;code&gt;abs()&lt;/code&gt; for your &lt;strong&gt;own data types&lt;/strong&gt; by implementing the &lt;code&gt;.__abs__()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;abs()&lt;/code&gt; function can process &lt;strong&gt;fractions&lt;/strong&gt; and &lt;strong&gt;decimals&lt;/strong&gt; from Python’s standard library.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Don’t worry if your mathematical knowledge of the absolute value function is a little rusty. You’ll begin by refreshing your memory before diving deeper into Python code. That said, feel free to skip the next section and jump right into the nitty-gritty details that follow.&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-absolute-value-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-absolute-value-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 find absolute values 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.437b3be14035.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 Find an Absolute Value 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-absolute-value/&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 Find the Absolute Value in Python&quot; src=&quot;https://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.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-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Find-Absolute-Values-in-Python_Watermarked.8fd4b05b9475.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.437b3be14035.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-absolute-value/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;How to Find an Absolute Value 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 knowledge of calculating absolute values in Python, mastering both built-in functions and common use cases to improve your coding accuracy.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;defining-the-absolute-value&quot;&gt;Defining the Absolute Value&lt;a class=&quot;headerlink&quot; href=&quot;#defining-the-absolute-value&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The absolute value lets you determine the &lt;strong&gt;size&lt;/strong&gt; or &lt;strong&gt;magnitude&lt;/strong&gt; of an object, such as a number or a &lt;a href=&quot;https://en.wikipedia.org/wiki/Vector_(mathematics_and_physics)&quot;&gt;vector&lt;/a&gt;, regardless of its direction. &lt;a href=&quot;https://en.wikipedia.org/wiki/Real_number&quot;&gt;Real numbers&lt;/a&gt; can have one of two directions when you ignore zero: they can be either positive or negative. On the other hand, &lt;a href=&quot;https://realpython.com/python-complex-numbers/&quot;&gt;complex numbers&lt;/a&gt; and vectors can have many more directions.&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 take the absolute value of a number, you lose information about its sign or, more generally, its direction.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Consider a temperature measurement as an example. If the thermometer reads -12°C, then you can say it’s twelve degrees Celsius below freezing. Notice how you decomposed the temperature in the last sentence into a magnitude, twelve, and a sign. The phrase &lt;em&gt;below freezing&lt;/em&gt; means the same as below zero degrees Celsius. The temperature’s size or absolute value is identical to the absolute value of the much warmer +12°C.&lt;/p&gt;
&lt;p&gt;Using mathematical notation, you can define the absolute value of 𝑥 as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Piecewise&quot;&gt;piecewise function&lt;/a&gt;, which behaves differently depending on the range of input values. A common symbol for absolute value consists of two vertical lines:&lt;/p&gt;
&lt;figure class=&quot;&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block w-50&quot; src=&quot;https://files.realpython.com/media/abs_pieceswise.850458ee3c6a.png&quot; width=&quot;731&quot; height=&quot;249&quot; srcset=&quot;/cdn-cgi/image/width=182,format=auto/https://files.realpython.com/media/abs_pieceswise.850458ee3c6a.png 182w, /cdn-cgi/image/width=243,format=auto/https://files.realpython.com/media/abs_pieceswise.850458ee3c6a.png 243w, /cdn-cgi/image/width=365,format=auto/https://files.realpython.com/media/abs_pieceswise.850458ee3c6a.png 365w, /cdn-cgi/image/width=731,format=auto/https://files.realpython.com/media/abs_pieceswise.850458ee3c6a.png 731w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Absolute Value Defined as a Piecewise Function&quot; data-asset=&quot;4505&quot;&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Absolute Value Defined as a Piecewise Function&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;This function returns values greater than or equal to zero without alteration. On the other hand, values smaller than zero have their sign flipped from a minus to a plus. Algebraically, this is equivalent to taking the square root of a number squared:&lt;/p&gt;
&lt;figure class=&quot;&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block w-33&quot; src=&quot;https://files.realpython.com/media/abs_algebraic.77816b2a997b.png&quot; width=&quot;350&quot; height=&quot;102&quot; srcset=&quot;/cdn-cgi/image/width=87,format=auto/https://files.realpython.com/media/abs_algebraic.77816b2a997b.png 87w, /cdn-cgi/image/width=116,format=auto/https://files.realpython.com/media/abs_algebraic.77816b2a997b.png 116w, /cdn-cgi/image/width=175,format=auto/https://files.realpython.com/media/abs_algebraic.77816b2a997b.png 175w, /cdn-cgi/image/width=350,format=auto/https://files.realpython.com/media/abs_algebraic.77816b2a997b.png 350w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Absolute Value Defined Algebraically&quot; data-asset=&quot;4506&quot;&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Absolute Value Defined Algebraically&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;When you square a real number, you always get a positive result, even if the number that you started with was negative. For example, the square of -12 and the square of 12 have the same value, equal to 144. Later, when you compute the square root of 144, you’ll only get 12 without the minus sign.&lt;/p&gt;
&lt;p&gt;Geometrically, you can think of an absolute value as the &lt;strong&gt;distance&lt;/strong&gt; from the origin, which is zero on a &lt;a href=&quot;https://en.wikipedia.org/wiki/Number_line&quot;&gt;number line&lt;/a&gt; in the case of the temperature reading from before:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/plot_number_line.293268c27c16.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/plot_number_line.293268c27c16.jpg&quot; width=&quot;1920&quot; height=&quot;600&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/plot_number_line.293268c27c16.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/plot_number_line.293268c27c16.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/plot_number_line.293268c27c16.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/plot_number_line.293268c27c16.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Absolute Value on a Number Line&quot; data-asset=&quot;4504&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Absolute Value on a Number Line&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;To calculate this distance, you can subtract the origin from the temperature reading (-12°C - 0°C = -12°C) or the other way around (0°C - (-12°C) = +12°C), and then drop the sign of the result. Subtracting zero doesn’t make much difference here, but the reference point may sometimes be shifted. That’s the case for vectors bound to a fixed point in space, which becomes their origin.&lt;/p&gt;
&lt;p&gt;Vectors, just like numbers, convey information about the &lt;strong&gt;direction&lt;/strong&gt; and the &lt;strong&gt;magnitude&lt;/strong&gt; of a physical quantity, but in more than one dimension. For example, you can express the &lt;a href=&quot;https://en.wikipedia.org/wiki/Velocity&quot;&gt;velocity&lt;/a&gt; of a falling snowflake as a three-dimensional vector:&lt;/p&gt;
&lt;figure&gt;
  &lt;div class=&quot;embed-responsive embed-responsive-16by9 rounded mb-3 &quot;&gt;
    &lt;iframe loading=&quot;lazy&quot; class=&quot;embed-responsive-item&quot; src=&quot;https://player.vimeo.com/video/734381007?background=1&quot; frameborder=&quot;0&quot; allow=&quot;fullscreen&quot; allowfullscreen&gt;&lt;/iframe&gt;
  &lt;/div&gt;

&lt;/figure&gt;

&lt;p&gt;This vector indicates the snowflake’s current position relative to the origin of the coordinate system. It also shows the snowflake’s direction and pace of motion through the space. The longer the vector, the greater the magnitude of the snowflake’s speed. As long as the coordinates of the vector’s initial and terminal points are expressed in meters, calculating its length will get you the snowflake’s &lt;a href=&quot;https://en.wikipedia.org/wiki/Speed&quot;&gt;speed&lt;/a&gt; measured in meters per unit of time.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; There are two ways to look at a vector. A &lt;em&gt;bound&lt;/em&gt; vector is an ordered pair of fixed points in space, whereas a &lt;em&gt;free&lt;/em&gt; vector only tells you about the displacement of the coordinates from point A to point B without revealing their absolute locations. Consider the following code snippet as an example:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;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.437b3be14035.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;A&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;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;B&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;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&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;bound_vector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&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;bound_vector&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[[1, 2, 3], [3, 2, 1]]&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;free_vector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;B&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;free_vector&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[2, 0, -2]&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.437b3be14035.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.437b3be14035.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;A bound vector wraps both points, providing quite a bit of information. In contrast, a free vector only represents the shift from A to B. You can calculate a free vector by subtracting the initial point, A, from the terminal one, B. One way to do so is by iterating over the consecutive pairs of coordinates with a &lt;a href=&quot;https://realpython.com/list-comprehension-python/&quot;&gt;list comprehension&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A free vector is essentially a bound vector translated to the origin of the coordinate system, so it begins at zero.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;length&lt;/strong&gt; of a vector, also known as its magnitude, is the distance between its initial and terminal points, 𝐴 and 𝐵, which you can calculate using the &lt;a href=&quot;https://en.wikipedia.org/wiki/Norm_(mathematics)#Euclidean_norm&quot;&gt;Euclidean norm&lt;/a&gt;:&lt;/p&gt;
&lt;figure class=&quot;&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block w-50&quot; src=&quot;https://files.realpython.com/media/abs_euclidean.7d19dd455597.png&quot; width=&quot;900&quot; height=&quot;400&quot; srcset=&quot;/cdn-cgi/image/width=225,format=auto/https://files.realpython.com/media/abs_euclidean.7d19dd455597.png 225w, /cdn-cgi/image/width=300,format=auto/https://files.realpython.com/media/abs_euclidean.7d19dd455597.png 300w, /cdn-cgi/image/width=450,format=auto/https://files.realpython.com/media/abs_euclidean.7d19dd455597.png 450w, /cdn-cgi/image/width=900,format=auto/https://files.realpython.com/media/abs_euclidean.7d19dd455597.png 900w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;The Length of a Bound Vector as a Euclidean Norm&quot; data-asset=&quot;4507&quot;&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;The Length of a Bound Vector as a Euclidean Norm&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;This formula calculates the length of the 𝑛-dimensional vector 𝐴𝐵, by summing the squares of the differences between the coordinates of points 𝐴 and 𝐵 in each dimension indexed by 𝑖. For a free vector, the initial point, 𝐴, becomes the origin of the coordinate system—or zero—which simplifies the formula, as you only need to square the coordinates of your vector.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-absolute-value/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-absolute-value/ »&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 Find an Absolute Value in Python</title>
      <id>https://realpython.com/quizzes/python-absolute-value/</id>
      <link href="https://realpython.com/quizzes/python-absolute-value/"/>
      <updated>2025-06-04T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your knowledge of calculating absolute values in Python, mastering both built-in functions and common use cases to improve your coding accuracy.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/python-absolute-value/&quot;&gt;How to Find an Absolute Value in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit key concepts such as how to use Python&amp;rsquo;s built-in functions to compute absolute values, apply them in mathematical operations, and handle different data types effectively.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Execute Your Python Scripts With a Shebang</title>
      <id>https://realpython.com/courses/execute-python-scripts-with-shebang/</id>
      <link href="https://realpython.com/courses/execute-python-scripts-with-shebang/"/>
      <updated>2025-06-03T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn when and how to use the shebang line in your Python scripts to execute them from a Unix-like shell.</summary>
      <content type="html">
        &lt;p&gt;In shell scripts, the shebang line (&lt;code&gt;#!&lt;/code&gt;) specifies the path to the interpreter that should execute the file. You can place it at the top of your Python file to tell the shell how to run your script, allowing you to execute the script directly without typing &lt;code&gt;python&lt;/code&gt; before the script name. The shebang is essential for Unix-like systems but ignored on Windows unless using specific compatibility layers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A shebang &lt;strong&gt;specifies the path to the Python interpreter&lt;/strong&gt; in scripts, allowing direct execution.&lt;/li&gt;
&lt;li&gt;You should &lt;strong&gt;include a shebang when a script needs direct execution&lt;/strong&gt;, but not in import-only modules.&lt;/li&gt;
&lt;li&gt;Best practices for shebangs include &lt;strong&gt;using &lt;code&gt;/usr/bin/env&lt;/code&gt; for portability&lt;/strong&gt; and ensuring the script is executable.&lt;/li&gt;
&lt;li&gt;Shebangs have limitations, such as being &lt;strong&gt;ignored on Windows&lt;/strong&gt; without compatibility layers like WSL.&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>How Can You Structure Your Python Script?</title>
      <id>https://realpython.com/python-script-structure/</id>
      <link href="https://realpython.com/python-script-structure/"/>
      <updated>2025-06-02T14:00:00+00:00</updated>
      <summary>Structure your Python script like a pro. This guide shows you how to organize your code, manage dependencies with PEP 723, and handle command-line arguments.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;You may have begun your Python journey interactively, exploring ideas within Jupyter Notebooks or through the Python REPL. While that’s great for quick experimentation and immediate feedback, you’ll likely find yourself saving code into &lt;code&gt;.py&lt;/code&gt; files. However, as your codebase grows, your Python script structure efficiency becomes increasingly important.&lt;/p&gt;
&lt;p&gt;Transitioning from interactive environments to structured scripts helps promote readability, enabling better collaboration and more robust development practices. This tutorial transforms messy scripts into well-organized, shareable code. Along the way, you’ll learn standard Python practices and tools. These techniques bridge the gap between quick scripting and disciplined software development.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll know how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Organize your Python scripts logically with &lt;strong&gt;functions&lt;/strong&gt;, &lt;strong&gt;constants&lt;/strong&gt;, and appropriate &lt;strong&gt;import&lt;/strong&gt; practices.&lt;/li&gt;
&lt;li&gt;Efficiently manage your script’s state using data structures such as &lt;strong&gt;enumerations&lt;/strong&gt; and &lt;strong&gt;data classes&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enhance interactivity through &lt;strong&gt;command-line arguments&lt;/strong&gt; and improve robustness with structured feedback using &lt;strong&gt;logging&lt;/strong&gt; and libraries like &lt;strong&gt;Rich&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;self-contained, shareable scripts&lt;/strong&gt; by handling dependencies inline using &lt;strong&gt;PEP 723&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Without further ado, it’s time to start working through a concrete script that interacts with a web server to obtain and manipulate a machine learning dataset.&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-script-structure-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-script-structure-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 how you can structure your Python script.&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.437b3be14035.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 Can You Structure Your Python Script?” 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-script-structure/&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 Can You Structure Your Python Script?&quot; src=&quot;https://files.realpython.com/media/How-Can-You-Structure-Your-Python-Script_Watermarked.680ffece0a52.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-Can-You-Structure-Your-Python-Script_Watermarked.680ffece0a52.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-Can-You-Structure-Your-Python-Script_Watermarked.680ffece0a52.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-Can-You-Structure-Your-Python-Script_Watermarked.680ffece0a52.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-Can-You-Structure-Your-Python-Script_Watermarked.680ffece0a52.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.437b3be14035.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-script-structure/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;How Can You Structure Your Python Script?&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 organizing and structuring Python scripts. You&#x27;ll revisit key concepts about best practices for writing clear, maintainable, and executable Python code.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;setting-the-stage-for-scripting&quot;&gt;Setting the Stage for Scripting&lt;a class=&quot;headerlink&quot; href=&quot;#setting-the-stage-for-scripting&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Throughout this tutorial, you’ll apply the structuring concepts by building a Python script step-by-step. The goal of this script will be to work with the well-known &lt;a href=&quot;https://archive.ics.uci.edu/dataset/53/iris&quot;&gt;Iris dataset&lt;/a&gt;, a classic dataset in &lt;a href=&quot;https://realpython.com/learning-paths/machine-learning-python/&quot;&gt;machine learning&lt;/a&gt; containing measurements for three species of Iris flowers.&lt;/p&gt;
&lt;p&gt;Your script, called &lt;code&gt;iris_summary.py&lt;/code&gt;, will evolve through several stages, demonstrating different structural improvements. These stages are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set Up the Initial Script:&lt;/strong&gt; Begin with a functional script using standard language features. Apply a foundational structure using named constants for clarity and the entry-point guard to separate executable code from importable definitions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Integrate External Libraries and Dependencies:&lt;/strong&gt; Incorporate third-party libraries when needed to leverage specialized functionality or simplify complex tasks. Declare and manage script dependencies within the file using standards like &lt;a href=&quot;https://peps.python.org/pep-0723/&quot;&gt;PEP 723&lt;/a&gt; for better reproducibility.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Handle Command-Line Arguments:&lt;/strong&gt; Add command-line arguments using helper libraries to make the script interactive and configurable. Define a clear &lt;code&gt;main()&lt;/code&gt; function to encapsulate the core script logic triggered by the command-line interface (CLI).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Structure Internal Data:&lt;/strong&gt;  Improve how data is represented by selecting appropriate data structures. Move beyond basic types and use constructs like &lt;a href=&quot;https://realpython.com/python-enum/&quot;&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/a&gt; for fixed choices, or &lt;a href=&quot;https://realpython.com/python-data-classes/&quot;&gt;&lt;code&gt;dataclass&lt;/code&gt;&lt;/a&gt;  and &lt;a href=&quot;https://realpython.com/python-namedtuple/&quot;&gt;&lt;code&gt;namedtuple&lt;/code&gt;&lt;/a&gt; for structured records.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Enhance Feedback and Robustness:&lt;/strong&gt; Refine how the script communicates its progress and results. Implement structured logging instead of relying solely on &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt;. Use &lt;a href=&quot;https://realpython.com/python-assert-statement/&quot;&gt;&lt;code&gt;assert&lt;/code&gt;&lt;/a&gt; statements for internal consistency checks during development, and improve the terminal output presentation, potentially using libraries designed for richer interfaces, like &lt;a href=&quot;https://realpython.com/python-rich-package/&quot;&gt;Rich&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;By following these steps, you’ll see how structure transforms a basic script into something more robust, readable, and shareable. Each new concept will be introduced and immediately applied to the evolving Iris script.&lt;/p&gt;
&lt;p&gt;Before diving into the specifics of script structure, it’s important to understand some foundational elements that make your Python scripts executable and well-organized.&lt;/p&gt;
&lt;h3 id=&quot;using-the-shebang-line&quot;&gt;Using the Shebang Line&lt;a class=&quot;headerlink&quot; href=&quot;#using-the-shebang-line&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;On &lt;a href=&quot;https://en.wikipedia.org/wiki/Unix-like&quot;&gt;Unix-like&lt;/a&gt; systems, such as Linux and macOS, you can make your Python script directly executable from the command line, like &lt;code&gt;./iris_summary.py&lt;/code&gt;, instead of always typing &lt;code&gt;python iris_summary.py&lt;/code&gt;. This involves making the file executable with &lt;code&gt;chmod +x iris_summary.py&lt;/code&gt;, and adding a &lt;a href=&quot;https://en.wikipedia.org/wiki/Shebang_(Unix)&quot;&gt;shebang line&lt;/a&gt; at the top of your file.&lt;/p&gt;
&lt;p&gt;The shebang tells the system which interpreter to use. The recommended, portable shebang for Python is:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;ch&quot;&gt;#!/usr/bin/env python3&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Your script logic goes here...&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.437b3be14035.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.437b3be14035.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 small addition signals that your file is intended to be run as a standalone script.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The dedicated tutorial &lt;a href=&quot;https://realpython.com/python-shebang/&quot;&gt;Executing Python Scripts With a Shebang&lt;/a&gt; provides a comprehensive look at how a shebang works, why &lt;code&gt;/usr/bin/env&lt;/code&gt; is used, how to handle arguments, and how to account for platform differences.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now that you know &lt;em&gt;how&lt;/em&gt; to tell the operating system how to run your script, you can focus on organizing the code within the script, starting with &lt;strong&gt;imports&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;organizing-the-import-statements&quot;&gt;Organizing the Import Statements&lt;a class=&quot;headerlink&quot; href=&quot;#organizing-the-import-statements&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;As your script starts interacting with more modules, the &lt;a href=&quot;https://docs.python.org/3/reference/simple_stmts.html#the-import-statement&quot;&gt;&lt;code&gt;import&lt;/code&gt; statements&lt;/a&gt; at the top of your file become important for clarity and &lt;a href=&quot;https://realpython.com/python-code-quality/&quot;&gt;code quality&lt;/a&gt;. Python’s official style guide, &lt;a href=&quot;https://realpython.com/python-pep8/&quot;&gt;PEP 8&lt;/a&gt;, recommends specific conventions for ordering imports, which significantly improves readability. Following these conventions is standard practice, and there are modern tools like &lt;a href=&quot;https://realpython.com/ruff-python/&quot;&gt;Ruff&lt;/a&gt; to enforce these conventions.&lt;/p&gt;
&lt;p&gt;Following a standard order helps anyone reading your code quickly understand its dependencies. The recommended grouping is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Standard Library Imports:&lt;/strong&gt; Modules included with Python, like &lt;a href=&quot;https://realpython.com/python-pathlib/&quot;&gt;&lt;code&gt;pathlib&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Third-Party Imports:&lt;/strong&gt; Libraries you’ve &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;installed with &lt;code&gt;pip&lt;/code&gt;&lt;/a&gt;, like &lt;a href=&quot;https://realpython.com/python-requests/&quot;&gt;&lt;code&gt;requests&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Local Imports:&lt;/strong&gt; Local modules, either application files or libraries, such as when importing another &lt;code&gt;.py&lt;/code&gt; file you wrote.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A good scripting practice for sharing code is to avoid local or library-specific imports and to ensure that only cross-platform third-party packages are used.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-script-structure/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-script-structure/ »&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 Can You Structure Your Python Script?</title>
      <id>https://realpython.com/quizzes/python-script-structure/</id>
      <link href="https://realpython.com/quizzes/python-script-structure/"/>
      <updated>2025-06-01T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of organizing and structuring Python scripts. You&#x27;ll revisit key concepts about best practices for writing clear, maintainable, and executable Python code.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the tutorial &lt;a href=&quot;https://realpython.com/python-script-structure/&quot;&gt;How Can You Structure Your Python Script?&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit best practices for organizing your Python scripts, including setting up the main entry point, using imports effectively, and writing code that can be reused as modules or run as standalone scripts.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #251: Python Thread Safety &amp; Managing Projects With uv</title>
      <id>https://realpython.com/podcasts/rpp/251/</id>
      <link href="https://realpython.com/podcasts/rpp/251/"/>
      <updated>2025-05-30T12:00:00+00:00</updated>
      <summary>What are the ways you can manage multithreaded code in Python? What synchronization techniques are available within Python&#x27;s threading module? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the ways you can manage multithreaded code in Python? What synchronization techniques are available within Python&#x27;s threading module? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Control Flow Structures in Python</title>
      <id>https://realpython.com/python-control-flow/</id>
      <link href="https://realpython.com/python-control-flow/"/>
      <updated>2025-05-28T14:00:00+00:00</updated>
      <summary>Take control of your code with Python control flow structures. You&#x27;ll learn with real examples using loops, conditionals, try-except blocks, and pattern matching.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python’s control flow structures allow you to dictate the order in which statements execute in your program. You can do this by using structures like conditionals, loops, and others.&lt;/p&gt;
&lt;p&gt;Normally, your code executes sequentially. You can modify this behavior using control flow structures that let you make decisions, run specific pieces of code in response to certain conditions, repeat a code block several times, and more.&lt;/p&gt;
&lt;p&gt;Knowing about control flow structures is a fundamental skill for you as a Python developer because they’ll allow you to fine-tune how your programs behave.&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;Control flow&lt;/strong&gt; in Python refers to the order in which code statements are executed or evaluated.&lt;/li&gt;
&lt;li&gt;Common &lt;strong&gt;control flow statements&lt;/strong&gt; in Python include conditionals with the &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elif&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt; keywords, loops with &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt;, exception handling with &lt;code&gt;try&lt;/code&gt; … &lt;code&gt;except&lt;/code&gt;, and structural pattern matching with &lt;code&gt;match&lt;/code&gt; … &lt;code&gt;case&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Control flow structures in Python let you &lt;strong&gt;make decisions&lt;/strong&gt;, &lt;strong&gt;repeat tasks&lt;/strong&gt;, and &lt;strong&gt;handle exceptions&lt;/strong&gt;, enhancing the dynamism and robustness of your code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To dive deeper into Python’s control flow, explore how these constructs allow you to write more dynamic and flexible programs by making decisions and handling repetitive tasks efficiently.&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-control-flow-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-control-flow-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 control flow structures 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.437b3be14035.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 “Control Flow Structures 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-control-flow/&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;Control Flow Structures in Python&quot; src=&quot;https://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.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.437b3be14035.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-control-flow/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Control Flow Structures 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 control flow structures, which include conditionals, loops, exception handling, and structural pattern matching. Strengthening these skills will help you write more dynamic, smart, and robust Python code.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-control-flow-in-python&quot;&gt;Getting to Know Control Flow in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-control-flow-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Most programming languages, including Python, execute code &lt;em&gt;sequentially&lt;/em&gt; from the top of the source file to the bottom, line by line. This way of running code is entirely logical. It’s like following a series of steps in order. However, what if you’re solving a problem with two or more action paths that depend on the result of evaluating a given condition?&lt;/p&gt;
&lt;p&gt;For example, say that you’re building an online store and need to implement a feature that decides whether a customer is eligible for free shipping. You’ve decided that if the order is greater than $150.00, then the customer gets free shipping. In this situation, you have two action paths:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If the order is less than $150.00, then the customer doesn’t get free shipping.&lt;/li&gt;
&lt;li&gt;If the order is equal to or greater than $150.00, then the customer gets free shipping.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now, think of a way you could do this with sequential statements. It isn’t an easy task, right? You’d need something that allows you to check the order and decide what course of action to take. That’s exactly what a conditional statement lets you do:&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.437b3be14035.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;order_total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;215.00&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;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order_total&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;150&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;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;You got free shipping!&quot;&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;else&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;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;The shipping fee is $5.00&quot;&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;You got free shipping!&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.437b3be14035.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.437b3be14035.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 how the code isn’t executed sequentially. Instead, the execution path depends on the condition’s result. Statements and syntax constructs that allow you to alter the normal execution flow as you did in the example above are known as &lt;strong&gt;control flow structures&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In programming, the ability of a program to choose between multiple paths of execution based on certain conditions is known as &lt;strong&gt;branching&lt;/strong&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In programming, the term &lt;a href=&quot;/ref/glossary/control-flow/&quot; class=&quot;ref-link&quot;&gt;&lt;strong&gt;control flow&lt;/strong&gt;&lt;/a&gt; refers to the order in which individual &lt;a href=&quot;/ref/glossary/statement/&quot; class=&quot;ref-link&quot;&gt;statements&lt;/a&gt; are executed or evaluated within a program. As you already know, the normal flow of execution is sequential. However, you can alter this by using control flow statements, which include &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;conditionals&lt;/a&gt;, &lt;a href=&quot;/ref/glossary/loop/&quot; class=&quot;ref-link&quot;&gt;loops&lt;/a&gt;, and several others.&lt;/p&gt;
&lt;p&gt;Here’s another example. This time, you need to repeat a task several times. You can do this by duplicating the same line of code as many times as needed:&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;greeting.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello!&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This code works. However, repeating the same code several times is error-prone and introduces &lt;a href=&quot;https://realpython.com/python-code-quality/#maintainability&quot;&gt;maintainability&lt;/a&gt; issues. Additionally, what if you don’t know the number of repetitions beforehand? In this situation, a loop will save you:&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.437b3be14035.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;_&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;3&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;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello!&quot;&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;Hello!&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Hello!&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Hello!&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you use 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 run the code three times. This code is much more elegant, flexible, and less repetitive.&lt;/p&gt;
&lt;p&gt;Control flow statements like these let you make decisions, repeat tasks, and handle exceptions, making your code more dynamic and powerful. In short, they let you customize the control flow of your programs. In the rest of this tutorial, you’ll dive into Python’s most commonly used control flow statements.&lt;/p&gt;
&lt;h2 id=&quot;using-conditional-statements&quot;&gt;Using Conditional Statements&lt;a class=&quot;headerlink&quot; href=&quot;#using-conditional-statements&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You took a quick peek at conditional statements in the previous section. A &lt;strong&gt;conditional statement&lt;/strong&gt; is a syntax construct that lets you execute certain code blocks only when a specific condition is true, while skipping them when the condition is false. It allows your programs to respond to different situations rather than just running sequentially.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-control-flow/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-control-flow/ »&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: Control Flow Structures in Python</title>
      <id>https://realpython.com/quizzes/python-control-flow/</id>
      <link href="https://realpython.com/quizzes/python-control-flow/"/>
      <updated>2025-05-28T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python control flow structures, which include conditionals, loops, exception handling, and structural pattern matching. Strengthening these skills will help you write more dynamic, smart, and robust Python code.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of control flow structures in Python. Control flow dictates the order in which your code executes, letting you make choices, repeat work, and handle exceptions to build more flexible, reliable programs. For hands-on examples and a deeper dive, check out the tutorial &lt;a href=&quot;https://realpython.com/python-control-flow/&quot;&gt;Control Flow Structures in Python&lt;/a&gt;.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The LEGB Rule &amp; Understanding Python Scope</title>
      <id>https://realpython.com/courses/legb-rule-python-scope/</id>
      <link href="https://realpython.com/courses/legb-rule-python-scope/"/>
      <updated>2025-05-27T14:00:00+00:00</updated>
      <summary>In this step-by-step video course, you&#x27;ll learn what scopes are, how they work, and how to use them effectively to avoid name collisions in your code.</summary>
      <content type="html">
        &lt;p&gt;The concept of &lt;strong&gt;scope&lt;/strong&gt; rules how &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt; and names are looked up in your code. It determines the visibility of a variable within the code. The scope of a name or variable depends on the place in your code where you create that variable. The Python scope concept is generally presented using a rule known as the &lt;strong&gt;LEGB rule&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The letters in the acronym LEGB stand for &lt;strong&gt;Local, Enclosing, Global, and Built-in&lt;/strong&gt; scopes. This summarizes not only the Python scope levels but also the sequence of steps that Python follows when resolving names in a program.&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;scopes&lt;/strong&gt; are and how they work in Python&lt;/li&gt;
&lt;li&gt;Why it&amp;rsquo;s important to know about &lt;strong&gt;Python scope&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;What the &lt;strong&gt;LEGB rule&lt;/strong&gt; is and how Python uses it to resolve names&lt;/li&gt;
&lt;li&gt;How to modify the &lt;strong&gt;standard behavior&lt;/strong&gt; of Python scope using &lt;code&gt;global&lt;/code&gt; and &lt;code&gt;nonlocal&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;scope-related tools&lt;/strong&gt; Python offers and how you can use them&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>marimo: A Reactive, Reproducible Notebook</title>
      <id>https://realpython.com/marimo-notebook/</id>
      <link href="https://realpython.com/marimo-notebook/"/>
      <updated>2025-05-26T14:00:00+00:00</updated>
      <summary>Discover how marimo notebook simplifies coding with reactive updates, UI elements, and sandboxing for safe, sharable notebooks.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;&lt;a href=&quot;https://marimo.io&quot;&gt;marimo notebooks&lt;/a&gt; redefine the notebook experience by offering a reactive environment that addresses the limitations of traditional linear notebooks. With marimo, you can seamlessly reproduce and share content while benefiting from automatic cell updates and a correct execution order. Discover how marimo’s features make it an ideal tool for documenting research and learning activities.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this tutorial, you’ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;marimo notebooks&lt;/strong&gt; automatically update dependent cells, ensuring consistent results across your work.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reactivity&lt;/strong&gt; allows marimo to determine the correct running order of cells using a &lt;strong&gt;directed acyclic graph (DAG)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sandboxing&lt;/strong&gt; in marimo creates isolated environments for notebooks, preventing package conflicts and ensuring reproducibility.&lt;/li&gt;
&lt;li&gt;You can add &lt;strong&gt;interactivity&lt;/strong&gt; to marimo notebooks using &lt;strong&gt;UI elements&lt;/strong&gt; like sliders and radio buttons.&lt;/li&gt;
&lt;li&gt;Traditional &lt;strong&gt;linear notebooks&lt;/strong&gt; have inherent flaws, such as hidden state issues, that marimo addresses with its reactive design.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before you can get started with marimo, you’ll need to install it. Fortunately, this is quick and easy to do:&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.437b3be14035.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;marimo
&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.437b3be14035.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.437b3be14035.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 use &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;&lt;code&gt;pip&lt;/code&gt;&lt;/a&gt; to install the marimo library on your system. With this done, it’s time to get started, be amazed, and learn all about a different type of notebook.&lt;/p&gt;
&lt;p&gt;The best way to approach this tutorial is to use the instructions to complete the various examples and try the exercises yourself. If you want copies of the various notebook files created during the tutorial, you’ll find them in your download bundle. The &lt;code&gt;README.md&lt;/code&gt; file provides further details of what’s in your downloads.&lt;/p&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.437b3be14035.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 “marimo: A Reactive, Reproducible Notebook” 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/marimo-notebook/&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;Marimo: A Reactive, Reproducible Notebook&quot; src=&quot;https://files.realpython.com/media/Showcase-Marimo-Notebook_Watermarked.91bd98028a40.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-Marimo-Notebook_Watermarked.91bd98028a40.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Showcase-Marimo-Notebook_Watermarked.91bd98028a40.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Showcase-Marimo-Notebook_Watermarked.91bd98028a40.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Showcase-Marimo-Notebook_Watermarked.91bd98028a40.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.437b3be14035.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/marimo-notebook/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;marimo: A Reactive, Reproducible Notebook&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;This quiz is a great way to reinforce and build on what you&#x27;ve learned about marimo notebooks. You&#x27;ll find most of the answers in the tutorial, but you&#x27;ll need to do some additional research to find some of the answers.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;how-to-get-started-in-a-marimo-notebook&quot;&gt;How to Get Started in a marimo Notebook&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-get-started-in-a-marimo-notebook&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A notebook is a file where you can write your programming code, run it, and view the output. You can add formatted text to explain how your code works, display charts to clarify results, and even allow your notebook’s users to try out different scenarios using a customized user interface. Once your notebook is complete, you can save everything in a single file and share your creation with others.&lt;/p&gt;
&lt;p&gt;In this section, you’ll learn to use marimo to create a simple notebook to perform a calculation and clearly display its results.&lt;/p&gt;
&lt;p&gt;Like many notebooks, marimo notebooks consist of cells. The primary cell types are &lt;strong&gt;code cells&lt;/strong&gt;, where you enter and run your Python code, and &lt;strong&gt;Markdown cells&lt;/strong&gt;, where you enter formatted text to augment the code and its output.&lt;/p&gt;
&lt;p&gt;In this first example, you’ll use a marimo notebook and &lt;a href=&quot;https://numpy.org/&quot;&gt;NumPy&lt;/a&gt; to solve a pair of &lt;a href=&quot;https://en.wikipedia.org/wiki/System_of_linear_equations&quot;&gt;simultaneous equations&lt;/a&gt;. To do this, you’ll first need to install the NumPy library:&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.437b3be14035.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;numpy
&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With &lt;a href=&quot;https://realpython.com/numpy-example/&quot;&gt;NumPy&lt;/a&gt; installed, you can now create your notebook by typing the following command into your console:&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.437b3be14035.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;marimo&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;edit&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;simultaneous_equations.py
&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.437b3be14035.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.437b3be14035.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 run this command, you’ll most likely create a new notebook named &lt;code&gt;simultaneous_equations.py&lt;/code&gt; for editing. If you already have a marimo notebook with that name, you’ll open it instead. Either way, your notebook will be ready for you to use within your browser.&lt;/p&gt;
&lt;p&gt;Switch to your web browser, and you’ll see your new notebook. It’ll contain a single cell. Hover your mouse over the cell to reveal a range of icons, each with a tooltip that explains its purpose and shows the associated keyboard shortcuts:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/ie_marimo_controls.a1f18e3fee0e.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block w-75&quot; src=&quot;https://files.realpython.com/media/ie_marimo_controls.a1f18e3fee0e.jpg&quot; width=&quot;1189&quot; height=&quot;500&quot; srcset=&quot;/cdn-cgi/image/width=297,format=auto/https://files.realpython.com/media/ie_marimo_controls.a1f18e3fee0e.jpg 297w, /cdn-cgi/image/width=396,format=auto/https://files.realpython.com/media/ie_marimo_controls.a1f18e3fee0e.jpg 396w, /cdn-cgi/image/width=594,format=auto/https://files.realpython.com/media/ie_marimo_controls.a1f18e3fee0e.jpg 594w, /cdn-cgi/image/width=1189,format=auto/https://files.realpython.com/media/ie_marimo_controls.a1f18e3fee0e.jpg 1189w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;graphic showing a marimo notebook cell and its controls.&quot; data-asset=&quot;6223&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;Each of the main icons are described in the screenshot above. While most of these are self-explanatory, there are some points you should be aware of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;em&gt;red trash can&lt;/em&gt; icon shown here won’t appear immediately in your notebook. This is used to delete a cell and will only appear when you add other cells. You can’t see it yet because all notebooks must have at least one cell. Deleting the last cell is impossible.&lt;/li&gt;
&lt;li&gt;The color of the &lt;em&gt;Run current cell&lt;/em&gt; icon is also significant. If this cell is white, as it is in the screenshot, it’s up to date and doesn’t need to be run. Once you start changing cells, you’ll see their &lt;em&gt;Run&lt;/em&gt; icons develop a yellow tinge. This warns you that the cell has become &lt;em&gt;stale&lt;/em&gt;, meaning you must run it to update it.&lt;/li&gt;
&lt;li&gt;Finally, notice that the numbers to the left of each cell indicate the line numbers of the code within the cell. Unlike most other notebooks, there are no numbers to indicate the running order of the cells. This is because marimo allows you to add code cells in any order. marimo can work out the correct cell running order for itself. Even so, placing cells in an illogical order should be avoided.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you hover your mouse over some of marimo’s icons, you’ll see their associated keyboard shortcuts. Unfortunately, they don’t work correctly in all browsers. If they don’t work for you, stick to using your mouse. Feel free to try them to find out if they work for you.&lt;/p&gt;
&lt;h3 id=&quot;adding-code-and-markdown-content&quot;&gt;Adding Code and Markdown Content&lt;a class=&quot;headerlink&quot; href=&quot;#adding-code-and-markdown-content&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;It’s time for you to gain experience creating some content in marimo. By following the walk-through, you’ll get hands-on practice with the basics.&lt;/p&gt;
&lt;p&gt;Although confusing the first time you see it, the single cell that contains &lt;code&gt;import marimo as mo&lt;/code&gt; is actually a blank cell. This code allows you to work with the &lt;a href=&quot;https://docs.marimo.io/api/&quot;&gt;marimo API&lt;/a&gt;. However, it’s not in the cell unless you type it in manually.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/marimo-notebook/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/marimo-notebook/ »&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: marimo: A Reactive, Reproducible Notebook</title>
      <id>https://realpython.com/quizzes/marimo-notebook/</id>
      <link href="https://realpython.com/quizzes/marimo-notebook/"/>
      <updated>2025-05-26T12:00:00+00:00</updated>
      <summary>This quiz is a great way to reinforce and build on what you&#x27;ve learned about marimo notebooks. You&#x27;ll find most of the answers in the tutorial, but you&#x27;ll need to do some additional research to find some of the answers.</summary>
      <content type="html">
        &lt;p&gt;Why not challenge yourself and see how much you know about marimo notebooks?&lt;/p&gt;
&lt;p&gt;Working your way through this quiz is a great way to reinforce and build on what you learned in the &lt;a href=&quot;https://realpython.com/marimo-notebook/&quot;&gt;marimo: A Reactive, Reproducible Notebook&lt;/a&gt; tutorial. &lt;/p&gt;
&lt;p&gt;You could try answering the questions without reading the tutorial first, but you&amp;rsquo;d miss out on a great learning experience!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #250: DjangoCon Europe 2025: Live Recording From Dublin</title>
      <id>https://realpython.com/podcasts/rpp/250/</id>
      <link href="https://realpython.com/podcasts/rpp/250/"/>
      <updated>2025-05-23T12:00:00+00:00</updated>
      <summary>What goes into making video courses at Real Python? How should you build an installable Django application? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What goes into making video courses at Real Python? How should you build an installable Django application? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Nested Loops in Python</title>
      <id>https://realpython.com/nested-loops-python/</id>
      <link href="https://realpython.com/nested-loops-python/"/>
      <updated>2025-05-21T14:00:00+00:00</updated>
      <summary>Learn how to use nested loops in Python to iterate over multiple sequences and perform repeated actions efficiently in your programs.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Nested loops in Python allow you to place one loop inside another, enabling you to perform repeated actions over multiple sequences. Understanding nested loops helps you write more efficient code, manage complex data structures, and avoid common pitfalls such as poor readability and performance issues.&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;Nested loops in Python involve &lt;strong&gt;placing one loop inside another&lt;/strong&gt;, enabling iteration over multiple sequences or repeated actions.&lt;/li&gt;
&lt;li&gt;Situations where nested loops are a good idea include &lt;strong&gt;handling multidimensional data&lt;/strong&gt;, &lt;strong&gt;generating patterns&lt;/strong&gt;, and &lt;strong&gt;performing repetitive tasks&lt;/strong&gt; with multiple layers of iteration.&lt;/li&gt;
&lt;li&gt;You can break out of nested loops by using the &lt;strong&gt;&lt;code&gt;break&lt;/code&gt; statement&lt;/strong&gt;, which exits the innermost loop when a condition is met.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disadvantages of nested loops&lt;/strong&gt; include potential performance bottlenecks, poor readability, and variable scoping issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This tutorial provides practical examples and optimization techniques for using nested loops effectively in your Python programs.&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/nested-loops-python-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-nested-loops-python-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to learn about nested loops 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.437b3be14035.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 “Nested Loops 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/nested-loops-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: #b9abe6;&quot; alt=&quot;Nested Loops in Python&quot; src=&quot;https://files.realpython.com/media/Nested-Loops-in-Python_Watermarked.0c20c531becf.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Nested-Loops-in-Python_Watermarked.0c20c531becf.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Nested-Loops-in-Python_Watermarked.0c20c531becf.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Nested-Loops-in-Python_Watermarked.0c20c531becf.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Nested-Loops-in-Python_Watermarked.0c20c531becf.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.437b3be14035.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/nested-loops-python/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Nested Loops in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Nested loops allow you to perform repeated actions over multiple sequences, but is there more? Test your understanding of nested loops in Python!&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-started-with-nested-loops-in-python&quot;&gt;Getting Started With Nested Loops in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-started-with-nested-loops-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Loops are fundamental building blocks in programming, allowing you to iterate through actions efficiently. In Python, there are two primary types of loops: the &lt;code&gt;for&lt;/code&gt; loop and the &lt;code&gt;while&lt;/code&gt; loop. Both serve the same purpose —executing a block of code multiple times—but they differ in how they operate and in their use cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt; iterates over a sequence, such as a &lt;a href=&quot;/ref/builtin-types/list/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;list&lt;/code&gt;&lt;/a&gt; or a &lt;a href=&quot;/ref/builtin-types/range/&quot; class=&quot;ref-link&quot;&gt;&lt;code&gt;range&lt;/code&gt;&lt;/a&gt;, and executes a block of code for each item. They’re useful when the number of iterations is known beforehand.&lt;/li&gt;
&lt;li&gt;A &lt;a href=&quot;https://realpython.com/python-while-loop/&quot;&gt;&lt;code&gt;while&lt;/code&gt; loop&lt;/a&gt; runs as long as a specified condition remains true, making it useful when the number of iterations isn’t known in advance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You create a nested loop by placing one loop inside another. This structure is especially helpful when working with multidimensional data, generating patterns, or handling tasks that involve several layers of repetition.&lt;/p&gt;
&lt;p&gt;In a nested loop, the first loop is called the &lt;strong&gt;outer loop&lt;/strong&gt;, and the loop inside is the &lt;strong&gt;inner loop&lt;/strong&gt;. So, for every iteration of the outer loop, the inner loop runs completely before the outer loop moves to the next iteration.&lt;/p&gt;
&lt;p&gt;Here’s the basic syntax of a nested loop:&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;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outer_variable&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outer_iterable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner_variable&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inner_iterable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&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.437b3be14035.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.437b3be14035.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;outer_iterable&lt;/code&gt; must be a &lt;a href=&quot;https://realpython.com/python-list/&quot;&gt;list&lt;/a&gt;, a &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt;, or some other &lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;sequence&lt;/a&gt; of items that you can iterate over. The same applies to the &lt;code&gt;inner_iterable&lt;/code&gt;. The &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; inside the inner loop contains the code that runs once for each &lt;code&gt;for&lt;/code&gt; loop step in the &lt;code&gt;inner_iterable&lt;/code&gt;. Since the inner loop is nested inside the outer loop, it runs in full for each iteration of the outer loop.&lt;/p&gt;
&lt;p&gt;A good analogy for a nested loop is the hour and minute hands of a clock. The hour hand moves slowly around the clock, completing one full revolution every twelve hours. Meanwhile, the minute hand moves at a much faster rate, completing a revolution every hour. While both hands rotate at different speeds, they work together, each completing their own cycle within the same clock.&lt;/p&gt;
&lt;p&gt;Here’s how the clock logic looks in Python 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.437b3be14035.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;hour&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;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;24&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;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;minute&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;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60&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;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hour&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;02d&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;minute&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;02d&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;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;00:00&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;00:01&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;00:02&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  ⋮&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;23:57&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;23:58&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;23:59&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.437b3be14035.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.437b3be14035.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, every time the minute hand completes a cycle, the hour hand moves to the next hour. &lt;code&gt;:02d&lt;/code&gt; is a &lt;a href=&quot;https://realpython.com/python-formatted-output/#format-specifiers-and-their-components&quot;&gt;format specifier&lt;/a&gt; that ensures the number is printed as a two-digit-wide integer value.&lt;/p&gt;
&lt;p&gt;Now that you’ve been introduced to nested loops, it’s time to explore some practical examples. You’ll become familiar with writing programs using nested loops in the following section.&lt;/p&gt;
&lt;h2 id=&quot;exploring-practical-examples-of-nested-loops&quot;&gt;Exploring Practical Examples of Nested Loops&lt;a class=&quot;headerlink&quot; href=&quot;#exploring-practical-examples-of-nested-loops&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;As you just learned, nested loops have a number of use cases. Here, you’ll have a look at a few examples. These examples are interesting and practical, allowing you to have fun as you explore their syntax and semantics.&lt;/p&gt;
&lt;h3 id=&quot;printing-patterns-with-nested-loops&quot;&gt;Printing Patterns With Nested Loops&lt;a class=&quot;headerlink&quot; href=&quot;#printing-patterns-with-nested-loops&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Being able to print any pattern of your choosing is a fascinating feat in programming. One way you can achieve this is by understanding how nested loops work. The code snippet below builds a sail pattern using a few simple symbols. While this may not seem particularly exciting, consider it a first step toward creating something spectacular—like a spaceship:&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.437b3be14035.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;linenos&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sail_patterns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;*#-x+o&quot;&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 3&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;row&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;n&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;pattern&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;spacing&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 6&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;symbol&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sail_patterns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 7&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;pattern&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;symbol&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;spacing&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 8&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 9&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;pattern&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;11&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;*     #     -     x     +     o&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;**    ##    --    xx    ++    oo&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;***   ###   ---   xxx   +++   ooo&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;****  ####  ----  xxxx  ++++  oooo&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;***** ##### ----- xxxxx +++++ ooooo&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.437b3be14035.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.437b3be14035.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’s what the code does line by line:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/nested-loops-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/nested-loops-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: Nested Loops in Python</title>
      <id>https://realpython.com/quizzes/nested-loops-python/</id>
      <link href="https://realpython.com/quizzes/nested-loops-python/"/>
      <updated>2025-05-21T12:00:00+00:00</updated>
      <summary>Nested loops allow you to perform repeated actions over multiple sequences, but is there more? Test your understanding of nested loops 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/nested-loops-python/&quot;&gt;Nested Loops in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Nested loops in Python involve placing one loop inside another, enabling iteration over multiple sequences or repeated actions. They&amp;rsquo;re particularly useful for handling multidimensional data, generating patterns, and performing repetitive tasks with multiple layers of iteration.&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>First Steps With LangChain</title>
      <id>https://realpython.com/courses/first-steps-langchain/</id>
      <link href="https://realpython.com/courses/first-steps-langchain/"/>
      <updated>2025-05-20T14:00:00+00:00</updated>
      <summary>Large language models (LLMs) have taken the world by storm. In this step-by-step video course, you&#x27;ll learn to use the LangChain library to build LLM-assisted applications.</summary>
      <content type="html">
        &lt;p&gt;You&amp;rsquo;ve likely interacted with large language models (LLMs), like the ones behind OpenAI&amp;rsquo;s ChatGPT, and experienced their remarkable ability to answer questions, summarize documents, write code, and much more.&lt;/p&gt;
&lt;p&gt;While LLMs are remarkable by themselves, with a little programming knowledge, you can leverage libraries like &lt;a href=&quot;https://python.langchain.com/docs/get_started/introduction&quot;&gt;LangChain&lt;/a&gt; to create your own LLM-powered applications that can do just about anything.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;LangChain&lt;/strong&gt; to build LLM-powered applications&lt;/li&gt;
&lt;li&gt;Create reusable instructions with &lt;strong&gt;prompt templates&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create and extend&lt;/strong&gt; LangChain chains&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Debug&lt;/strong&gt; what happens when a chain executes&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: How to Group Data Using Polars .group_by()</title>
      <id>https://realpython.com/quizzes/polars-groupby/</id>
      <link href="https://realpython.com/quizzes/polars-groupby/"/>
      <updated>2025-05-19T12:00:00+00:00</updated>
      <summary>Put your Polars .group_by() and aggregation skills to the test. This quiz goes beyond the tutorial, so you&#x27;ll need to dig deeper to find all the answers.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the techniques covered in
&lt;a href=&quot;https://realpython.com/polars-groupby/&quot;&gt;How to Group Data Using Polars .group_by()&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through the questions, you&amp;rsquo;ll review your understanding of how to use the data aggregation and grouping techniques provided by Polars.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll need to do some research outside of the tutorial to answer all the questions, so let this challenge take you on a learning journey.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #249: Going Beyond requirements.txt With pylock.toml and PEP 751</title>
      <id>https://realpython.com/podcasts/rpp/249/</id>
      <link href="https://realpython.com/podcasts/rpp/249/"/>
      <updated>2025-05-16T12:00:00+00:00</updated>
      <summary>What is the best way to record the Python dependencies for the reproducibility of your projects? What advantages will lock files provide for those projects? This week on the show, we welcome back Python Core Developer Brett Cannon to discuss his journey to bring PEP 751 and the pylock.toml file format to the community.</summary>
      <content type="html">
        &lt;p&gt;What is the best way to record the Python dependencies for the reproducibility of your projects? What advantages will lock files provide for those projects? This week on the show, we welcome back Python Core Developer Brett Cannon to discuss his journey to bring PEP 751 and the pylock.toml file format to the community.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Working With Missing Data in Polars</title>
      <id>https://realpython.com/courses/missing-data-polars/</id>
      <link href="https://realpython.com/courses/missing-data-polars/"/>
      <updated>2025-05-13T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to deal with missing data in Polars to ensure it doesn&#x27;t interfere with your data analysis. You&#x27;ll discover how to check for missing values, update them, and remove them.</summary>
      <content type="html">
        &lt;p&gt;Efficiently handling missing data in Polars is essential for keeping your datasets clean during analysis. Polars provides powerful tools to identify, replace, and remove null values, ensuring seamless data processing.&lt;/p&gt;
&lt;p&gt;This video course covers practical techniques for managing missing data and highlights Polars&amp;rsquo; capabilities to enhance your data analysis workflow. By following along, you&amp;rsquo;ll gain hands-on experience with these techniques and learn how to ensure your datasets are accurate and reliable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand that:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Polars&lt;/strong&gt; allows you to handle missing data using &lt;strong&gt;LazyFrames&lt;/strong&gt; and &lt;strong&gt;DataFrames&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;check for null values&lt;/strong&gt; in Polars using the &lt;code&gt;.null_count()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NaN&lt;/strong&gt; represents non-numeric values while &lt;strong&gt;null&lt;/strong&gt; indicates missing data.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;replace NaN&lt;/strong&gt; in Polars by converting them to nulls and using &lt;code&gt;.fill_null()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;fix missing data&lt;/strong&gt; by identifying, replacing, or removing null values.&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: Getting Started With Python IDLE</title>
      <id>https://realpython.com/quizzes/python-idle/</id>
      <link href="https://realpython.com/quizzes/python-idle/"/>
      <updated>2025-05-13T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python IDLE, the default integrated development environment (IDE) that comes bundled with every Python installation. You&#x27;ll revisit how to interact with Python directly in IDLE, edit and execute Python files.</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-idle/&quot;&gt;Python IDLE&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Python IDLE is an IDE included with Python installations, designed for basic editing, execution, and debugging of Python code. You can also customize IDLE to make it a useful tool for writing Python.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #248: Experiments With Gen AI, Knowledge Graphs, Workflows, and Python</title>
      <id>https://realpython.com/podcasts/rpp/248/</id>
      <link href="https://realpython.com/podcasts/rpp/248/"/>
      <updated>2025-05-09T12:00:00+00:00</updated>
      <summary>Are you looking for some projects where you can practice your Python skills? Would you like to experiment with building a generative AI app or an automated knowledge graph sentiment analysis tool? This week on the show, we speak with Raymond Camden about his journey into Python, his work in developer relations, and the Python projects featured on his blog.</summary>
      <content type="html">
        &lt;p&gt;Are you looking for some projects where you can practice your Python skills? Would you like to experiment with building a generative AI app or an automated knowledge graph sentiment analysis tool? This week on the show, we speak with Raymond Camden about his journey into Python, his work in developer relations, and the Python projects featured on his blog.&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 the Python subprocess Module</title>
      <id>https://realpython.com/courses/python-subprocess-module/</id>
      <link href="https://realpython.com/courses/python-subprocess-module/"/>
      <updated>2025-05-06T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to use Python’s subprocess module to run and control external programs from your scripts. You&#x27;ll start with launching basic processes and progress to interacting with them as they execute.</summary>
      <content type="html">
        &lt;p&gt;Python&amp;rsquo;s &lt;code&gt;subprocess&lt;/code&gt; module allows you to run shell commands and manage external processes directly from your Python code. By using &lt;code&gt;subprocess&lt;/code&gt;, you can execute shell commands like &lt;code&gt;ls&lt;/code&gt; or &lt;code&gt;dir&lt;/code&gt;, launch applications, and handle both input and output streams. This module provides tools for error handling and process communication, making it a flexible choice for integrating command-line operations into your Python projects.&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 Python &lt;code&gt;subprocess&lt;/code&gt; module is used to &lt;strong&gt;run shell commands&lt;/strong&gt; and manage external processes.&lt;/li&gt;
&lt;li&gt;You run a shell command using &lt;code&gt;subprocess&lt;/code&gt; by &lt;strong&gt;calling &lt;code&gt;subprocess.run()&lt;/code&gt;&lt;/strong&gt; with the command as a list of arguments.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;subprocess.call()&lt;/code&gt;, &lt;code&gt;subprocess.run()&lt;/code&gt;, and &lt;code&gt;subprocess.Popen()&lt;/code&gt; differ in &lt;strong&gt;how they execute commands&lt;/strong&gt; and handle process output and return codes.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;multiprocessing&lt;/code&gt; is for &lt;strong&gt;parallel execution&lt;/strong&gt; within Python, while &lt;code&gt;subprocess&lt;/code&gt; manages &lt;strong&gt;external processes&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To execute multiple commands in sequence using &lt;code&gt;subprocess&lt;/code&gt;, you can chain them by &lt;strong&gt;using pipes or running them consecutively&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 Logging With the Loguru Library</title>
      <id>https://realpython.com/quizzes/python-loguru/</id>
      <link href="https://realpython.com/quizzes/python-loguru/"/>
      <updated>2025-05-06T12:00:00+00:00</updated>
      <summary>Think you know Python logging? Take this quick Loguru quiz to test your knowledge of formatting, sinks, rotation, and more!</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/python-loguru/&quot;&gt;How to Use Loguru for Simpler Python Logging&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit key concepts like installing Loguru, basic logging, formatting, sinks, log rotation, and capturing exception information.&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>Thread Safety in Python: Locks and Other Techniques</title>
      <id>https://realpython.com/courses/thread-safety-locks-other-techniques/</id>
      <link href="https://realpython.com/courses/thread-safety-locks-other-techniques/"/>
      <updated>2025-04-29T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn about the issues that can occur when your code is run in a multithreaded environment. Then you&#x27;ll explore the various synchronization primitives available in Python&#x27;s threading module, such as locks, which help you make your code safe.</summary>
      <content type="html">
        &lt;p&gt;Threads share state in your programs, which means race conditions can be created when two or more threads fight to update a value. This course is about the various primitives you can use to ensure atomic access to your program&amp;rsquo;s shared state.&lt;/p&gt;
&lt;p&gt;By the end of this video course, you&amp;rsquo;ll be able to identify safety issues and prevent them by using the synchronization primitives in Python&amp;rsquo;s &lt;code&gt;threading&lt;/code&gt; module to make your code thread-safe.&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;thread safety&lt;/strong&gt; is&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;race conditions&lt;/strong&gt; are and how to avoid them&lt;/li&gt;
&lt;li&gt;How to identify &lt;strong&gt;thread safety issues&lt;/strong&gt; in your code&lt;/li&gt;
&lt;li&gt;What different &lt;strong&gt;synchronization primitives&lt;/strong&gt; exist in the &lt;code&gt;threading&lt;/code&gt; module&lt;/li&gt;
&lt;li&gt;How to use synchronization primitives to &lt;strong&gt;make your code thread-safe&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 #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>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>
  

</feed>
