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

  
    <entry>
      <title>Jinja Templating</title>
      <id>https://realpython.com/courses/jinja-templating/</id>
      <link href="https://realpython.com/courses/jinja-templating/"/>
      <updated>2023-06-27T14:00:00+00:00</updated>
      <summary>With Jinja, you can build rich templates that power the front end of your web applications. But you can use Jinja without a web framework running in the background. Anytime you want to create text files with programmatic content, Jinja can help you out.</summary>
      <content type="html">
        &lt;p&gt;Templates are an essential ingredient in full-stack web development.
With &lt;strong&gt;Jinja&lt;/strong&gt;, you can build rich templates that power the front end of your Python web applications.&lt;/p&gt;
&lt;p&gt;Jinja is a text templating language. It allows you to process a block of text, insert values from a context dictionary, control how the text flows using conditionals and loops, modify inserted data with filters, and compose different templates together using inheritance and inclusion.&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;Install the Jinja &lt;strong&gt;template engine&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Create your first Jinja &lt;strong&gt;template&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Render a Jinja template in &lt;strong&gt;Flask&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;code&gt;for&lt;/code&gt; loops&lt;/strong&gt; and &lt;strong&gt;conditional statements&lt;/strong&gt; with Jinja&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nest&lt;/strong&gt; Jinja templates&lt;/li&gt;
&lt;li&gt;Modify variables in Jinja with &lt;strong&gt;filters&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;macros&lt;/strong&gt; to add functionality to your front end&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This video course is for you if you want to learn more about the Jinja template language or if you&amp;rsquo;re getting started with Flask.&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 Flatten a List of Lists in Python</title>
      <id>https://realpython.com/python-flatten-list/</id>
      <link href="https://realpython.com/python-flatten-list/"/>
      <updated>2023-06-26T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to flatten a list of lists in Python. You&#x27;ll use different tools and techniques to accomplish this task. First, you&#x27;ll use a loop along with the .extend() method of list. Then you&#x27;ll explore other tools, including reduce(), sum(), itertools.chain(), and more.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Sometimes, when you’re working with data, you may have the data as a list of nested lists. A common operation is to &lt;strong&gt;flatten&lt;/strong&gt; this data into a one-dimensional list in Python. Flattening a list involves converting a multidimensional list, such as a matrix, into a one-dimensional list.&lt;/p&gt;
&lt;p&gt;To better illustrate what it means to flatten a list, say that you have the following matrix of numeric values:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;matrix&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;gp&quot;&gt;... &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;3&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;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;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;2&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;gp&quot;&gt;... &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;4&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;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;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;0&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;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;matrix&lt;/code&gt; variable holds a Python &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;list&lt;/a&gt; that contains four nested lists. Each nested list represents a row in the matrix. The rows store four items or numbers each. Now say that you want to turn this matrix into the following list:&lt;/p&gt;
&lt;div class=&quot;highlight python&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&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;8&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;2&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;6&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;3&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;1&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;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;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;How do you manage to flatten your matrix and get a one-dimensional list like the one above? In this tutorial, you’ll learn how to do that in Python.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-flatten-list-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-flatten-list-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that showcases and compares several ways to flatten a list of lists in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;how-to-flatten-a-list-of-lists-with-a-for-loop&quot;&gt;How to Flatten a List of Lists With a &lt;code&gt;for&lt;/code&gt; Loop&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-flatten-a-list-of-lists-with-a-for-loop&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;How can you flatten a list of lists in Python? In general, to flatten a list of lists, you can run the following steps either explicitly or implicitly:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Create&lt;/strong&gt; a new empty list to store the &lt;strong&gt;flattened data&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Iterate&lt;/strong&gt; over each &lt;strong&gt;nested list&lt;/strong&gt; or sublist in the original list.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add&lt;/strong&gt; every &lt;strong&gt;item&lt;/strong&gt; from the current sublist to the list of flattened data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Return&lt;/strong&gt; the resulting list with the &lt;strong&gt;flattened data&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can follow several paths and use multiple tools to run these steps in Python. Arguably, the most natural and readable way to do this is to 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;, which allows you to explicitly iterate over the sublists.&lt;/p&gt;
&lt;p&gt;Then you need a way to add items to the new flattened list. For that, you have a couple of valid options. First, you’ll turn to the &lt;code&gt;.extend()&lt;/code&gt; method from the &lt;code&gt;list&lt;/code&gt; class itself, and then you’ll give the &lt;a href=&quot;https://realpython.com/python-assignment-operator/#augmented-assignments-for-concatenation-and-repetition&quot;&gt;augmented concatenation operator&lt;/a&gt; (&lt;code&gt;+=&lt;/code&gt;) a go.&lt;/p&gt;
&lt;p&gt;To continue with the &lt;code&gt;matrix&lt;/code&gt; example, here’s how you would translate these steps into Python code using a &lt;code&gt;for&lt;/code&gt; loop and the &lt;code&gt;.extend()&lt;/code&gt; method:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;flatten_extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;flat_list&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;gp&quot;&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;n&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;flat_list&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&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;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flat_list&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Inside &lt;code&gt;flatten_extend()&lt;/code&gt;, you first create a new empty list called &lt;code&gt;flat_list&lt;/code&gt;. You’ll use this list to store the flattened data when you extract it from &lt;code&gt;matrix&lt;/code&gt;. Then you start a loop to iterate over the inner, or nested, lists from &lt;code&gt;matrix&lt;/code&gt;. In this example, you use the name &lt;code&gt;row&lt;/code&gt; to represent the current nested list.&lt;/p&gt;
&lt;p&gt;In every iteration, you use &lt;code&gt;.extend()&lt;/code&gt; to add the content of the current sublist to &lt;code&gt;flat_list&lt;/code&gt;. This method takes an &lt;a href=&quot;https://realpython.com/python-iterators-iterables/&quot;&gt;iterable&lt;/a&gt; as an argument and appends its items to the end of the target list.&lt;/p&gt;
&lt;p&gt;Now go ahead and run the following code to check that your function does the job:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;flatten_extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[9, 3, 8, 3, 4, 5, 2, 8, 6, 4, 3, 1, 1, 0, 4, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That’s neat! You’ve flattened your first list of lists. As a result, you have a one-dimensional list containing all the numeric values from &lt;code&gt;matrix&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;.extend()&lt;/code&gt;, you’ve come up with a Pythonic and readable way to flatten your lists. You can get the same result using the &lt;a href=&quot;https://realpython.com/python-assignment-operator/#augmented-assignments-for-concatenation-and-repetition&quot;&gt;augmented concatenation operator&lt;/a&gt; (&lt;code&gt;+=&lt;/code&gt;) on your &lt;code&gt;flat_list&lt;/code&gt; object. However, this alternative approach may not be as readable:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;flatten_concatenation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;flat_list&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;gp&quot;&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;n&quot;&gt;matrix&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;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;flat_list&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&gt;&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flat_list&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This function is similar to &lt;code&gt;flatten_extend()&lt;/code&gt;. The only difference is that you’ve replaced the call to &lt;code&gt;.extend()&lt;/code&gt; with an augmented concatenation. Concatenations like this allow you to append a list of items to the end of an existing list.&lt;/p&gt;
&lt;p&gt;Go ahead and call this function with &lt;code&gt;matrix&lt;/code&gt; as an argument:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;flatten_concatenation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;matrix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[9, 3, 8, 3, 4, 5, 2, 8, 6, 4, 3, 1, 1, 0, 4, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This call to &lt;code&gt;flatten_concatenation()&lt;/code&gt; returns the same result as your previous &lt;code&gt;flatten_extend()&lt;/code&gt;. Both functions are equivalent and interchangeable. Their goal is to flatten a list of lists. So, it’s up to you to decide which one to use in your code. However, readability-wise, &lt;code&gt;flatten_extend()&lt;/code&gt; seems to be a better solution.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-flatten-list/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-flatten-list/ »&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 #161: Resources and Advice for Building CircuitPython Projects</title>
      <id>https://realpython.com/podcasts/rpp/161/</id>
      <link href="https://realpython.com/podcasts/rpp/161/"/>
      <updated>2023-06-23T12:00:00+00:00</updated>
      <summary>Are you looking to advance your CircuitPython projects? Would you like a collection of resources and tools to help you along your path? This week on the show, Tod Kurt is here to discuss building projects with CircuitPython.</summary>
      <content type="html">
        &lt;p&gt;Are you looking to advance your CircuitPython projects? Would you like a collection of resources and tools to help you along your path? This week on the show, Tod Kurt is here to discuss building projects with CircuitPython.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python&#x27;s Self Type: How to Annotate Methods That Return self</title>
      <id>https://realpython.com/python-type-self/</id>
      <link href="https://realpython.com/python-type-self/"/>
      <updated>2023-06-21T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use the Self type hint in Python to annotate methods that return an instance of their own class. You&#x27;ll gain hands-on experience with type hints and annotations of methods that return an instance of their class, making your code more readable and maintainable.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Have you ever found yourself lost in a big repository of Python code, struggling to keep track of the intended types of variables? Without the proper use of &lt;a href=&quot;https://realpython.com/python-type-checking/&quot;&gt;type hints&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-type-checking/#annotations&quot;&gt;annotations&lt;/a&gt;, uncovering variable types can become a tedious and time-consuming task. Perhaps you’re an avid user of type hints but aren’t sure how to annotate methods that return &lt;strong&gt;&lt;code&gt;self&lt;/code&gt;&lt;/strong&gt; or other &lt;strong&gt;instances&lt;/strong&gt; of the class itself. That’s the issue that you’ll tackle in this tutorial.&lt;/p&gt;
&lt;p&gt;First, though, you’ll need to understand what type hints are and how they work. Type hints allow you to explicitly indicate variable types, function arguments, and return values. This can make your code more readable and maintainable, especially as it grows in size and complexity.&lt;/p&gt;
&lt;p&gt;You specify &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/#argument-passing&quot;&gt;function&lt;/a&gt; argument types with a colon (&lt;code&gt;:&lt;/code&gt;) then the &lt;a href=&quot;https://realpython.com/python-data-types/&quot;&gt;data type&lt;/a&gt;, while return value annotations use a dash–greater than symbol (&lt;code&gt;-&amp;gt;&lt;/code&gt;) then the &lt;a href=&quot;https://realpython.com/python-return-statement/&quot;&gt;return&lt;/a&gt; type. To see an example, you can write a function that accepts as input the number of pies that you bought and the price per pie then outputs a &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;string&lt;/a&gt; summarizing your transaction:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;buy_pies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num_pies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;price_per_pie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;total_cost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num_pies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;price_per_pie&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Yum! You spent $&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total_cost&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; dollars on &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;num_pies&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; pies!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In &lt;code&gt;buy_pies()&lt;/code&gt;, you type the &lt;code&gt;num_pies&lt;/code&gt; variable with &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;price_per_pie&lt;/code&gt; with &lt;code&gt;float&lt;/code&gt;. You annotate the return value with the &lt;code&gt;str&lt;/code&gt; type because it returns a string.&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; It’s possible to type hint the &lt;code&gt;total_cost&lt;/code&gt; local variable as &lt;code&gt;total_cost: float&lt;/code&gt;. While this may seem like a good idea, the type checker can automatically infer the type of &lt;code&gt;total_cost&lt;/code&gt; from &lt;code&gt;num_pies&lt;/code&gt; and &lt;code&gt;price_per_pie&lt;/code&gt;, making the annotation unnecessary for &lt;code&gt;total_cost&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Types and annotations in Python usually don’t affect the functionality of the code, but many &lt;a href=&quot;https://realpython.com/python-type-checking/#static-type-checking&quot;&gt;static type checkers&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-ides-code-editors-guide/&quot;&gt;IDEs&lt;/a&gt; recognize them. For instance, if you hover over &lt;code&gt;buy_pies()&lt;/code&gt; in &lt;a href=&quot;https://realpython.com/python-development-visual-studio-code/&quot;&gt;VS Code&lt;/a&gt;, then you can see the type of each argument or return value:&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/831693880?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;You can also use annotations when working with classes. This can help other developers understand which return type to expect from a method, which can be especially useful when working with complex class hierarchies. You can even annotate methods that return an instance of the class.&lt;/p&gt;
&lt;p&gt;One use case for types and annotations is to annotate methods that return an instance of their class. This is particularly useful for &lt;a href=&quot;https://realpython.com/instance-class-and-static-methods-demystified/&quot;&gt;class methods&lt;/a&gt; and can prevent the confusion that arises when working with inheritance and method chaining. Unfortunately, annotating these methods can be confusing and cause unexpected errors. A natural way to annotate such a method is to use the class name, but the following won’t work:&lt;/p&gt;
&lt;div class=&quot;highlight python&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# incorrect_self_type.py&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;typing&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Queue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Any&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;p&quot;&gt;[]&lt;/span&gt;

&lt;span class=&quot;hll&quot;&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;enqueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Queue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;/span&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&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;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the example above, &lt;code&gt;.enqueue()&lt;/code&gt; from &lt;a href=&quot;https://realpython.com/queue-in-python/&quot;&gt;&lt;code&gt;Queue&lt;/code&gt;&lt;/a&gt; appends an item to the queue and returns the class instance. While it might seem intuitive to annotate &lt;code&gt;.enqueue()&lt;/code&gt; with the class name, this causes both static type checking and runtime errors. Most static type checkers realize that &lt;code&gt;Queue&lt;/code&gt; isn’t defined before it’s used, and if you try to run the code, then you’ll get the following &lt;a href=&quot;https://realpython.com/python-traceback/#nameerror&quot;&gt;&lt;code&gt;NameError&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight pytb&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
  &lt;span class=&quot;c&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;NameError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;name &#x27;Queue&#x27; is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There would also be issues when inheriting from &lt;code&gt;Queue&lt;/code&gt;. In particular, a method like &lt;code&gt;.enqueue()&lt;/code&gt; would return &lt;code&gt;Queue&lt;/code&gt; even if you called it on a subclass of &lt;code&gt;Queue&lt;/code&gt;. Python’s &lt;code&gt;Self&lt;/code&gt; type can handle these situations, offering a compact and readable annotation that takes care of the subtleties of annotating methods returning an instance of the enclosing class.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll explore the &lt;code&gt;Self&lt;/code&gt; type in detail and learn how to use it to write more readable and maintainable code. In particular, you’ll see how to annotate a method with the &lt;code&gt;Self&lt;/code&gt; type and make sure your IDE will recognize this. You’ll also examine alternative strategies for annotating methods that return a class instance and explore why the &lt;code&gt;Self&lt;/code&gt; type is preferred.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-type-self-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-type-self-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the sample code&lt;/a&gt; that you’ll use to annotate methods with Python’s &lt;code&gt;Self&lt;/code&gt; type.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;how-to-annotate-a-method-with-the-self-type-in-python&quot;&gt;How to Annotate a Method With the Self Type in Python&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-annotate-a-method-with-the-self-type-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Due to its intuitive and concise syntax, as defined by &lt;a href=&quot;https://peps.python.org/pep-0673/&quot;&gt;PEP 673&lt;/a&gt;, the &lt;code&gt;Self&lt;/code&gt; type is the preferred annotation for methods that return an instance of their class. The &lt;code&gt;Self&lt;/code&gt; type can be imported directly from Python’s &lt;code&gt;typing&lt;/code&gt; module in &lt;a href=&quot;https://realpython.com/python311-new-features/#improved-type-variables&quot;&gt;version 3.11&lt;/a&gt; and beyond. For Python versions less than 3.11, the &lt;code&gt;Self&lt;/code&gt; type is available in &lt;code&gt;typing_extensions&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As an example, you’ll annotate a &lt;a href=&quot;https://realpython.com/how-to-implement-python-stack/&quot;&gt;stack&lt;/a&gt; data structure. Pay particular attention to your &lt;code&gt;.push()&lt;/code&gt; annotation:&lt;/p&gt;
&lt;div class=&quot;highlight python&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;c1&quot;&gt;# stack.py&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;linenos&quot;&gt; 3&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;typing&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Stack&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;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 7&lt;/span&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Any&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;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 8&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;linenos&quot;&gt; 9&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;linenos&quot;&gt;10&lt;/span&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&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;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;11&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;12&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;13&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;14&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;fm&quot;&gt;__bool__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;15&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;16&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;17&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;ValueError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Stack is empty&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;18&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;19&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot;&gt;__bool__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;20&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;return&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;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You import the &lt;code&gt;Self&lt;/code&gt; type from &lt;code&gt;typing&lt;/code&gt; in line 3 and annotate &lt;code&gt;.push()&lt;/code&gt; with &lt;code&gt;-&amp;gt; Self&lt;/code&gt; in line 9. This tells static type checkers that &lt;code&gt;.push()&lt;/code&gt; returns a &lt;code&gt;Stack&lt;/code&gt; instance, allowing you to confidently chain multiple pushes together. Note that it’s usually not necessary to annotate &lt;a href=&quot;https://realpython.com/python-classes/#instance-methods-with-self&quot;&gt;&lt;code&gt;self&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/instance-class-and-static-methods-demystified/#instance-class-and-static-methods-an-overview&quot;&gt;&lt;code&gt;cls&lt;/code&gt;&lt;/a&gt; parameters, as discussed in &lt;a href=&quot;https://peps.python.org/pep-0484/#annotating-instance-and-class-methods&quot;&gt;PEP 484&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may have noticed that you implement &lt;code&gt;.__bool__()&lt;/code&gt; to check whether the stack is empty. This method is a part of &lt;a href=&quot;https://realpython.com/operator-function-overloading/#the-python-data-model&quot;&gt;Python’s data model&lt;/a&gt; and is known as a dunder or special method. In this case, defining &lt;code&gt;.__bool__()&lt;/code&gt; allows you to call the &lt;code&gt;bool()&lt;/code&gt; built-in function from either inside or outside the class to check whether the stack is empty.&lt;/p&gt;
&lt;p&gt;The inclusion of &lt;code&gt;.__bool__()&lt;/code&gt; enables the utilization of the class in Pythonic conditionals, such as &lt;code&gt;if not stack: ...&lt;/code&gt;, as the expression within an &lt;code&gt;if&lt;/code&gt; statement is assessed using &lt;code&gt;bool()&lt;/code&gt; internally. This forms the basis for determining whether values are deemed &lt;em&gt;truthy&lt;/em&gt; or &lt;em&gt;falsy&lt;/em&gt; in &lt;a href=&quot;https://realpython.com/python-boolean/&quot;&gt;Boolean&lt;/a&gt; terms.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-type-self/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-type-self/ »&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>Recursion in Python</title>
      <id>https://realpython.com/courses/python-recursion/</id>
      <link href="https://realpython.com/courses/python-recursion/"/>
      <updated>2023-06-20T14:00:00+00:00</updated>
      <summary>A recursive function is one that calls itself. In this video course, you&#x27;ll see what recursion is, how it works in Python, and under what circumstances you should use it.</summary>
      <content type="html">
        &lt;p&gt;If you&amp;rsquo;re familiar with &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions in Python&lt;/a&gt;, then you know that it&amp;rsquo;s quite common for one function to call another. In Python, it&amp;rsquo;s also possible for a function to call itself!  A function that calls itself is said to be &lt;strong&gt;recursive&lt;/strong&gt;, and the technique of employing a recursive function is called &lt;strong&gt;recursion&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It may seem peculiar for a function to call itself, but many types of programming problems are best expressed recursively. When you bump up against such a problem, recursion is an indispensable tool for you to have in your toolkit.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this video course, you&amp;rsquo;ll understand:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What it means for a function to call itself &lt;strong&gt;recursively&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;When recursion might be your &lt;strong&gt;best best&lt;/strong&gt; for solving a problem&lt;/li&gt;
&lt;li&gt;How you can &lt;strong&gt;implement recursion&lt;/strong&gt; for various use cases in Python&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Along the way, you&amp;rsquo;ll study several specific programming tasks where you can use recursion in Python. You&amp;rsquo;ll also explore alternatives to recursion.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python&#x27;s raise: Effectively Raising Exceptions in Your Code</title>
      <id>https://realpython.com/python-raise-exception/</id>
      <link href="https://realpython.com/python-raise-exception/"/>
      <updated>2023-06-19T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to raise exceptions in Python, which will improve your ability to efficiently handle errors and exceptional situations in your code. This way, you&#x27;ll write more reliable, robust, and maintainable code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In your Python journey, you’ll come across situations where you need to signal that something is going wrong in your code. For example, maybe a file doesn’t exist, a network or database connection fails, or your code gets invalid input. A common approach to tackle these issues is to &lt;strong&gt;raise an exception&lt;/strong&gt;, notifying the user that an error has occurred. That’s what Python’s &lt;code&gt;raise&lt;/code&gt; statement is for.&lt;/p&gt;
&lt;p&gt;Learning about the &lt;code&gt;raise&lt;/code&gt; statement allows you to effectively handle errors and exceptional situations in your code. This way, you’ll develop more robust programs and higher-quality code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Raise exceptions in Python using the &lt;strong&gt;&lt;code&gt;raise&lt;/code&gt;&lt;/strong&gt; statement&lt;/li&gt;
&lt;li&gt;Decide &lt;strong&gt;which exceptions&lt;/strong&gt; to raise and &lt;strong&gt;when&lt;/strong&gt; to raise them in your code&lt;/li&gt;
&lt;li&gt;Explore common &lt;strong&gt;use cases&lt;/strong&gt; for raising exceptions in Python&lt;/li&gt;
&lt;li&gt;Apply &lt;strong&gt;best practices&lt;/strong&gt; for raising exceptions in your Python code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should understand the fundamentals of Python, including &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-data-types/&quot;&gt;data types&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;conditional&lt;/a&gt; statements, &lt;a href=&quot;https://realpython.com/python-exceptions/&quot;&gt;exception&lt;/a&gt; handling, and &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-raise-exception-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-raise-exception-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the sample code&lt;/a&gt; that you’ll use to gracefully raise and handle exceptions in your Python code.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;handling-exceptional-situations-in-python&quot;&gt;Handling Exceptional Situations in Python&lt;a class=&quot;headerlink&quot; href=&quot;#handling-exceptional-situations-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://realpython.com/python-exceptions/&quot;&gt;Exceptions&lt;/a&gt; play a fundamental role in Python. They allow you to handle &lt;strong&gt;errors&lt;/strong&gt; and &lt;strong&gt;exceptional situations&lt;/strong&gt; in your code. But what is an exception? An exception represents an error or indicates that something is going wrong. Some programming languages, such as &lt;a href=&quot;https://realpython.com/c-for-python-programmers/&quot;&gt;C&lt;/a&gt;, and &lt;a href=&quot;https://go.dev/&quot;&gt;Go&lt;/a&gt;, encourage you to return error codes, which you &lt;em&gt;check&lt;/em&gt;. In contrast, Python encourages you to raise exceptions, which you &lt;em&gt;handle&lt;/em&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 Python, not all exceptions are errors. The built-in &lt;a href=&quot;https://docs.python.org/3/library/exceptions.html#StopIteration&quot;&gt;&lt;code&gt;StopIteration&lt;/code&gt;&lt;/a&gt; exception is an excellent example of this. Python internally uses this exception to terminate the iteration over &lt;a href=&quot;https://realpython.com/python-iterators-iterables/&quot;&gt;iterators&lt;/a&gt;. Python exceptions that represent errors have the &lt;code&gt;Error&lt;/code&gt; suffix attached to their names.&lt;/p&gt;
&lt;p&gt;Python also has a specific category of exceptions that represent &lt;a href=&quot;https://docs.python.org/3/library/exceptions.html#warnings&quot;&gt;warnings&lt;/a&gt; to the programmer. Warnings come in handy when you need to alert the user of some condition in a program. However, that condition may not warrant raising an exception and terminating the program. A common example of a warning is &lt;a href=&quot;https://docs.python.org/3/library/exceptions.html#DeprecationWarning&quot;&gt;&lt;code&gt;DeprecationWarning&lt;/code&gt;&lt;/a&gt;, which appears when you use deprecated features.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;When a problem occurs in a program, Python automatically raises an exception. For example, watch what happens if you try to access a nonexistent index in a &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;&lt;code&gt;list&lt;/code&gt;&lt;/a&gt; object:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;colors&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;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;s2&quot;&gt;&quot;red&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;s2&quot;&gt;&quot;orange&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;s2&quot;&gt;&quot;yellow&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;s2&quot;&gt;&quot;green&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;s2&quot;&gt;&quot;blue&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;s2&quot;&gt;&quot;indigo&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;s2&quot;&gt;&quot;violet&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &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;colors&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;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
  File &lt;span class=&quot;nb&quot;&gt;&quot;&amp;lt;stdin&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;gr&quot;&gt;IndexError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;list index out of range&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this example, your &lt;code&gt;colors&lt;/code&gt; list doesn’t have a &lt;code&gt;10&lt;/code&gt; index. Its indices go from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;6&lt;/code&gt;, covering your seven colors. So, if you try to get index number &lt;code&gt;10&lt;/code&gt;, then you get an &lt;a href=&quot;https://realpython.com/python-traceback/#indexerror&quot;&gt;&lt;code&gt;IndexError&lt;/code&gt;&lt;/a&gt; exception telling you that your target index is out of range.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In the example above, Python raised the exception on its own, which it’ll only do with &lt;a href=&quot;#raising-built-in-exceptions&quot;&gt;built-in exceptions&lt;/a&gt;. You, as a programmer, have the option to raise built-in or custom exceptions, as you’ll learn in the section &lt;a href=&quot;#choosing-the-exception-to-raise-built-in-vs-custom&quot;&gt;Choosing the Exception to Raise: Built-in vs Custom&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Every raised exception has a &lt;a href=&quot;https://realpython.com/python-traceback/&quot;&gt;traceback&lt;/a&gt;, also known as a &lt;strong&gt;stack trace&lt;/strong&gt;, &lt;strong&gt;stack traceback&lt;/strong&gt;, or &lt;strong&gt;backtrace&lt;/strong&gt;, among other names. A traceback is a report containing the sequence of calls and operations that traces down to the current exception.&lt;/p&gt;
&lt;p&gt;In Python, the traceback header is &lt;code&gt;Traceback (most recent call last)&lt;/code&gt; in most situations. Then you’ll have the actual call stack and the exception name followed by its error message.&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; Since the introduction of the new &lt;a href=&quot;https://realpython.com/python39-new-features/#a-more-powerful-python-parser&quot;&gt;PEG parser&lt;/a&gt; in Python &lt;a href=&quot;https://realpython.com/python39-new-features/&quot;&gt;3.9&lt;/a&gt;, there’s been an ongoing effort to make the &lt;a href=&quot;https://realpython.com/python311-error-messages/&quot;&gt;error messages&lt;/a&gt; in tracebacks more helpful and specific. This effort continues to produce new results, and Python 3.12 has incorporated &lt;a href=&quot;https://realpython.com/python312-error-messages/&quot;&gt;even better error messages&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Exceptions will cause your program to terminate unless you handle them using a &lt;a href=&quot;https://realpython.com/python-exceptions/#the-try-and-except-block-handling-exceptions&quot;&gt;&lt;code&gt;try&lt;/code&gt; … &lt;code&gt;except&lt;/code&gt;&lt;/a&gt; block:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;IndexError&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;Your list doesn&#x27;t have that index :-(&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;Your list doesn&#x27;t have that index :-(&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first step in handling an exception is to &lt;em&gt;predict which exceptions can happen&lt;/em&gt;. If you don’t do that, then you can’t handle the exceptions, and your program will crash. In that situation, Python will print the exception traceback so that you can figure out how to fix the problem. Sometimes, you must let the program fail in order to discover the exceptions that it raises.&lt;/p&gt;
&lt;p&gt;In the above example, you know beforehand that indexing a list with an index beyond its range will raise an &lt;code&gt;IndexError&lt;/code&gt; exception. So, you’re ready to catch and handle that specific exception. The &lt;code&gt;try&lt;/code&gt; block takes care of catching exceptions. The &lt;code&gt;except&lt;/code&gt; clause specifies the exception that you’re predicting, and the &lt;code&gt;except&lt;/code&gt; code block allows you to take action accordingly. The whole process is known as &lt;strong&gt;exception handling&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If your code raises an exception in a function but doesn’t handle it there, then the exception propagates to where you called function. If your code doesn’t handle it there either, then it continues propagating until it reaches the main program. If there’s no exception handler there, then the program halts with an exception traceback.&lt;/p&gt;
&lt;p&gt;Exceptions are everywhere in Python. Virtually every module in the &lt;a href=&quot;https://docs.python.org/3/library/index.html&quot;&gt;standard library&lt;/a&gt; uses them. Python will raise exceptions in many different circumstances. The Python documentation states that:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Exceptions are a means of breaking out of the normal flow of control of a code block in order to handle errors or other exceptional conditions. An exception is &lt;em&gt;raised&lt;/em&gt; at the point where the error is detected; it may be &lt;em&gt;handled&lt;/em&gt; by the surrounding code block or by any code block that directly or indirectly invoked the code block where the error occurred. (&lt;a href=&quot;https://docs.python.org/3/reference/executionmodel.html#exceptions&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In short, Python automatically raises exceptions when an error occurs during a program’s execution. Python also allows you to raise exceptions on demand using the &lt;code&gt;raise&lt;/code&gt; keyword. This keyword lets you handle your program’s errors in a more controlled manner.&lt;/p&gt;
&lt;h2 id=&quot;raising-exceptions-in-python-the-raise-statement&quot;&gt;Raising Exceptions in Python: The &lt;code&gt;raise&lt;/code&gt; Statement&lt;a class=&quot;headerlink&quot; href=&quot;#raising-exceptions-in-python-the-raise-statement&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-raise-exception/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-raise-exception/ »&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 #160: Inheriting a Large Python Code Base &amp; Building a GUI With Kivy</title>
      <id>https://realpython.com/podcasts/rpp/160/</id>
      <link href="https://realpython.com/podcasts/rpp/160/"/>
      <updated>2023-06-16T12:00:00+00:00</updated>
      <summary>What are the unique challenges of a large Python code base? What techniques can you implement to simplify the management of a big project? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the unique challenges of a large Python code base? What techniques can you implement to simplify the management of a big project? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>How to Make Engaging Programming Videos</title>
      <id>https://realpython.com/how-to-make-programming-videos/</id>
      <link href="https://realpython.com/how-to-make-programming-videos/"/>
      <updated>2023-06-14T14:00:00+00:00</updated>
      <summary>Creating a screencast can be a great way for you to to share your knowledge and help fellow developers on your team. However, not all video tutorials are equally effective. In this tutorial, you&#x27;ll learn how to make engaging and informative programming videos that will impress your peers.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;&lt;a href=&quot;https://realpython.com/courses/&quot;&gt;Programming videos&lt;/a&gt; have become an increasingly popular medium for sharing knowledge and helping the fellow developers on your team. Especially when you’re working remotely, effective communication is vital, and screencasts have emerged as a powerful tool that meets this need. That’s why knowing how to make programming videos is a valuable skill, no matter where you are in your career.&lt;/p&gt;
&lt;p&gt;Even if you’ve never considered creating video content yourself, creating a screencast can be a great way to enhance written documentation or demonstrate complex processes as a professional programmer. Often, a two-minute video helps your colleagues more than a wordy email. Other times, an in-depth thirty-minute video is more convincing than an hour-long meeting.&lt;/p&gt;
&lt;p&gt;However, not all videos are equally effective. To create engaging and informative programming screencasts, you should keep some important details in mind.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Know when the &lt;strong&gt;video format&lt;/strong&gt; is the right choice&lt;/li&gt;
&lt;li&gt;Set up your machine to &lt;strong&gt;record screencasts&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prepare&lt;/strong&gt; the content and the code&lt;/li&gt;
&lt;li&gt;Be a captivating &lt;strong&gt;programming instructor&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handle mistakes&lt;/strong&gt; while filming&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Export&lt;/strong&gt; and &lt;strong&gt;share&lt;/strong&gt; your video&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the end, you’ll be equipped with the knowledge and skills to produce screencasts that make a meaningful impact on your viewers.&lt;/p&gt;
&lt;p&gt;If you’re using VS Code and want to have a distraction-free environment in your code editor while recording, then you can download a handy settings file for VS Code by clicking the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/how-to-make-programming-videos-file/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-how-to-make-programming-videos-file&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the settings file&lt;/a&gt; that you can use to create a clean, readable VS Code editor for your programming video tutorials.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;decide-when-a-programming-video-makes-sense&quot;&gt;Decide When a Programming Video Makes Sense&lt;a class=&quot;headerlink&quot; href=&quot;#decide-when-a-programming-video-makes-sense&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Not every idea that you want to get across is worth recording a video for.
But the more experienced you are with hitting the record button, the more convenient it’ll be to use the video format instead of writing.&lt;/p&gt;
&lt;p&gt;There are three common tasks where a video can come in handy:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Showing off a new feature&lt;/li&gt;
&lt;li&gt;Asking for help with a bug&lt;/li&gt;
&lt;li&gt;Giving visual feedback on a program&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;While your desired outcome for each of these use cases is probably different, the preparation for each of them is quite similar. 
In this section, you’ll explore how to tackle a process that applies to all the tasks so you know what you want to talk about in your recording.&lt;/p&gt;
&lt;h3 id=&quot;focus-on-the-outcome&quot;&gt;Focus on the Outcome&lt;a class=&quot;headerlink&quot; href=&quot;#focus-on-the-outcome&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you decide to create a programming video, then it’s important to focus on the outcome that you want to achieve. By clearly defining your desired outcome, you can structure your video in a way that effectively communicates the key points and ensures that your viewers gain the intended knowledge or understanding.&lt;/p&gt;
&lt;p&gt;When showcasing key features, your objective could be to demonstrate the core functionality of a &lt;a href=&quot;https://realpython.com/python-package-quality/&quot;&gt;high-quality Python package&lt;/a&gt; or a new framework that you’re trying out. In these cases, you may want to provide step-by-step instructions and examples to help viewers understand and use the package effectively on their machines.&lt;/p&gt;
&lt;p&gt;Other times, you may want to provide constructive feedback on the user interface of an application. For example, maybe you want to share your thoughts on the &lt;a href=&quot;https://realpython.com/flask-javascript-frontend-for-rest-api/&quot;&gt;front end of a Flask API&lt;/a&gt;. Then your objective could be to highlight potential improvements, usability concerns, and design recommendations.&lt;/p&gt;
&lt;p&gt;Another outcome of a screencast could be to guide viewers through the process of identifying a specific bug. This might include explaining the symptoms and potential causes then troubleshooting steps to narrow down and locate the issue effectively.&lt;/p&gt;
&lt;p&gt;Some people are often more inclined to watch a short video instead of taking the same time to read. So if you’re looking for help in an &lt;a href=&quot;https://realpython.com/community-slack-guide/&quot;&gt;online Python community&lt;/a&gt;, then a small screencast can be a great way to illustrate your problem. &lt;/p&gt;
&lt;h3 id=&quot;sketch-out-code-examples&quot;&gt;Sketch Out Code Examples&lt;a class=&quot;headerlink&quot; href=&quot;#sketch-out-code-examples&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Chances are that you’ll include some code in your programming videos. You may showcase snippets or perform live coding. Either way, it’s crucial to sketch out the code examples beforehand.&lt;/p&gt;
&lt;p&gt;Preparing code examples allows you to iterate how you want to present your code before you start filming. Here are some ideas of how you can sketch out your code examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Plan the structure:&lt;/strong&gt; Outline the code examples in advance to determine their logical structure and flow. This helps present the code coherently, making it easier for your viewers to follow along and understand the concepts that you explain.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Clarify your key points:&lt;/strong&gt; Refine and clarify the key points that you want to convey. Identify and highlight crucial aspects of the code, ensuring that you address essential concepts and techniques effectively.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ensure the code is correct:&lt;/strong&gt; Test the code snippets beforehand to verify their correctness. This ensures that they produce the desired output or functionality during the recording, allowing you to deliver &lt;a href=&quot;https://realpython.com/python-pep8/&quot;&gt;accurate and well-formatted Python code&lt;/a&gt; to your viewers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optimize for presentation:&lt;/strong&gt; Optimize the code for presentation purposes by removing irrelevant segments, simplifying complex sections, or deleting unnecessary &lt;a href=&quot;https://realpython.com/python-type-checking/#annotations&quot;&gt;type annotations&lt;/a&gt;. This makes your Python code examples concise, focused, and readily comprehensible for your audience.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By preparing your code, you ensure that it’s clean, organized, and operational, resulting in a seamless and effective learning experience for your viewers.&lt;/p&gt;
&lt;h3 id=&quot;take-speaker-notes&quot;&gt;Take Speaker Notes&lt;a class=&quot;headerlink&quot; href=&quot;#take-speaker-notes&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/how-to-make-programming-videos/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/how-to-make-programming-videos/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Basics: Reading and Writing Files</title>
      <id>https://realpython.com/courses/python-reading-and-writing-files/</id>
      <link href="https://realpython.com/courses/python-reading-and-writing-files/"/>
      <updated>2023-06-13T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to move data back and forth between your Python programs and external software by reading and writing files. You&#x27;ll practice reading and writing data stored in the CSV file format, one of the most widely supported file formats for transferring tabular data.</summary>
      <content type="html">
        &lt;p&gt;Files are everywhere in the modern world. They&amp;rsquo;re the medium in which data is digitally stored and transferred. Chances are, you&amp;rsquo;ve opened dozens, if not hundreds, of files just today! Now it&amp;rsquo;s time to read and write files with Python.&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;Understand the difference between &lt;strong&gt;text&lt;/strong&gt; and &lt;strong&gt;binary&lt;/strong&gt; files&lt;/li&gt;
&lt;li&gt;Learn about &lt;strong&gt;character encodings&lt;/strong&gt; and &lt;strong&gt;line endings&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Work with &lt;strong&gt;file objects&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;Read and write character data in various &lt;strong&gt;file modes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;open()&lt;/code&gt;, &lt;code&gt;Path.open()&lt;/code&gt;, and the &lt;code&gt;with&lt;/code&gt; statement&lt;/li&gt;
&lt;li&gt;Take advantage of the &lt;code&gt;csv&lt;/code&gt; module to manipulate &lt;strong&gt;CSV data&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This video course is part of the Python Basics series, which accompanies &lt;a href=&quot;https://realpython.com/products/python-basics-book/&quot;&gt;&lt;em&gt;Python Basics: A Practical Introduction to Python 3&lt;/em&gt;&lt;/a&gt;. You can also check out the other &lt;a href=&quot;https://realpython.com/learning-paths/python-basics/&quot;&gt;Python Basics courses&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Note that you&amp;rsquo;ll be using &lt;a href=&quot;https://realpython.com/python-idle/&quot;&gt;IDLE&lt;/a&gt; to &lt;a href=&quot;https://realpython.com/interacting-with-python/&quot;&gt;interact with Python&lt;/a&gt; throughout this course. If you&amp;rsquo;re just getting started, then you might want to check out &lt;a href=&quot;https://realpython.com/courses/setting-up-python/&quot;&gt;Python Basics: Setting Up Python&lt;/a&gt; before diving into this course.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python News: What&#x27;s New From May 2023</title>
      <id>https://realpython.com/python-news-may-2023/</id>
      <link href="https://realpython.com/python-news-may-2023/"/>
      <updated>2023-06-12T14:00:00+00:00</updated>
      <summary>May 2023 was an exciting month for Python developers. Python 3.12 is getting closer to its final release as it enters the beta stage. All presentations from PyCon US are available to everyone on video. And a new Python-based programming language is generating a lot of buzz.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;May 2023 was an important month for Python, as the upcoming &lt;strong&gt;Python 3.12 version&lt;/strong&gt; is now &lt;strong&gt;feature complete&lt;/strong&gt;. You can dig into a lot of information about Python and its development by reading the coverage of the &lt;strong&gt;Language Summit&lt;/strong&gt; and watching videos from &lt;strong&gt;PyCon US&lt;/strong&gt;. Modular has announced a &lt;strong&gt;new programming language&lt;/strong&gt; that’s based on Python.&lt;/p&gt;
&lt;p&gt;Grab a cup of your favorite beverage and sit down with the most important Python news from the last month. &lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;&lt;p&gt;&lt;strong&gt;Join Now:&lt;/strong&gt; &lt;a href=&quot;&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-newsletter&quot; data-focus=&quot;false&quot;&gt;Click here to join the Real Python Newsletter&lt;/a&gt; and you&#x27;ll never miss another Python tutorial, course update, or post.&lt;/p&gt;&lt;/div&gt;

&lt;h2 id=&quot;python-312-in-beta&quot;&gt;Python 3.12 in Beta&lt;a class=&quot;headerlink&quot; href=&quot;#python-312-in-beta&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Since 2019, a new version of Python has been released every year in October. The next version of Python–Python 3.12—is no different. Its release is planned for &lt;a href=&quot;https://peps.python.org/pep-0693/&quot;&gt;October 2, 2023&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Python 3.12 reached an important milestone last month when its &lt;a href=&quot;https://www.python.org/downloads/release/python-3120b1/&quot;&gt;first beta version&lt;/a&gt; was released. A &lt;strong&gt;beta release&lt;/strong&gt; is an early release of an upcoming Python version. In contrast to &lt;strong&gt;alpha releases&lt;/strong&gt;, which have been available for a while, the betas are &lt;strong&gt;feature complete&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;Being feature complete means that there’ll be no features added to Python 3.12 that aren’t already in the beta version. Instead, the time until the final release in October will focus on finding and fixing bugs and other issues. The core developers ask for your help:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We strongly encourage maintainers of third-party Python projects to test with 3.12 during the beta phase and report issues found to &lt;a href=&quot;https://github.com/python/cpython/issues&quot;&gt;the Python bug tracker&lt;/a&gt; as soon as possible. (&lt;a href=&quot;https://www.python.org/downloads/release/python-3120b2/&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You should &lt;a href=&quot;https://realpython.com/python-pre-release/&quot;&gt;install the beta version&lt;/a&gt; and test that your code still works. Finding bugs during the beta phase is an important and impactful way to &lt;a href=&quot;https://realpython.com/start-contributing-python/&quot;&gt;contribute to Python&lt;/a&gt;. If you maintain a package on &lt;a href=&quot;https://realpython.com/pypi-publish-python-package/&quot;&gt;PyPI&lt;/a&gt;, then you can help the community by running &lt;a href=&quot;https://realpython.com/pytest-python-testing/&quot;&gt;tests&lt;/a&gt; and publishing &lt;a href=&quot;https://realpython.com/python-wheels/&quot;&gt;wheels&lt;/a&gt; for Python 3.12.&lt;/p&gt;
&lt;p&gt;You can learn about all the upcoming features from &lt;a href=&quot;https://docs.python.org/3.12/whatsnew/3.12.html&quot;&gt;What’s New in Python 3.12&lt;/a&gt;. Some highlights are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python312-error-messages/&quot;&gt;Ever better error messages&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;More powerful &lt;a href=&quot;https://realpython.com/python-f-strings/&quot;&gt;f-strings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Better support for sub-interpreters&lt;/li&gt;
&lt;li&gt;Improved &lt;a href=&quot;https://realpython.com/python-type-checking/#static-typing&quot;&gt;static typing&lt;/a&gt; features&lt;/li&gt;
&lt;li&gt;Support for the Linux perf profiler&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In addition, the &lt;a href=&quot;https://github.com/faster-cpython/&quot;&gt;Faster CPython project&lt;/a&gt; continues to deliver performance improvements, and Python 3.12 will be even faster than &lt;a href=&quot;https://realpython.com/python311-new-features/&quot;&gt;Python 3.11&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-may-2023/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-may-2023/ »&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 #159: Volunteering, Organizing, and Finding a Python Community</title>
      <id>https://realpython.com/podcasts/rpp/159/</id>
      <link href="https://realpython.com/podcasts/rpp/159/"/>
      <updated>2023-06-09T12:00:00+00:00</updated>
      <summary>Have you thought about getting more involved in the Python community? Are you interested in volunteering for an event or becoming an organizer? This week on the show, we speak with organizers from this year&#x27;s PyCascades conference about making connections, learning new skills, and rationing your time.</summary>
      <content type="html">
        &lt;p&gt;Have you thought about getting more involved in the Python community? Are you interested in volunteering for an event or becoming an organizer? This week on the show, we speak with organizers from this year&#x27;s PyCascades conference about making connections, learning new skills, and rationing your time.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>What&#x27;s the Zen of Python?</title>
      <id>https://realpython.com/zen-of-python/</id>
      <link href="https://realpython.com/zen-of-python/"/>
      <updated>2023-06-07T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll be exploring the Zen of Python, a collection of nineteen guiding principles for writing idiomatic Python. You&#x27;ll find out how they originated and whether you should follow them. Along the way, you&#x27;ll uncover several inside jokes associated with this humorous poem.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;If you’ve been learning Python long enough, then you’ve likely seen or heard about the &lt;strong&gt;Zen of Python&lt;/strong&gt;. Experienced Pythonistas often refer to it as a source of wisdom and guidance, especially when they want to settle an argument about certain design decisions in a piece of code. Others take these principles even more seriously by considering them a sort of Pythonic &lt;a href=&quot;https://www.merriam-webster.com/dictionary/decalogue&quot;&gt;decalogue&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll learn where to find the Zen of Python, how it came into existence, and how to interpret its mysterious aphorisms. You don’t need to be a Python master to understand the Zen of Python! But you do need to answer an important question: &lt;strong&gt;What exactly is the Zen of Python?&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-easter-eggs/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-easter-eggs&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download your Easter egg hunt&lt;/a&gt; to discover what’s hidden inside Python!&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;in-short-its-a-humorous-poem-listing-python-philosophies&quot;&gt;In Short: It’s a Humorous Poem Listing Python Philosophies&lt;a class=&quot;headerlink&quot; href=&quot;#in-short-its-a-humorous-poem-listing-python-philosophies&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;According to the &lt;a href=&quot;https://docs.python.org/3/glossary.html&quot;&gt;Python glossary&lt;/a&gt;, which contains definitions of popular terms related to this programming language, the &lt;strong&gt;Zen of Python&lt;/strong&gt; is a:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Listing of Python design principles and philosophies that are helpful in understanding and using the language. The listing can be found by typing “&lt;code&gt;import this&lt;/code&gt;” at the interactive prompt. (&lt;a href=&quot;https://docs.python.org/3/glossary.html#term-Zen-of-Python&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Indeed, when you type the indicated &lt;a href=&quot;https://realpython.com/python-import/&quot;&gt;&lt;code&gt;import&lt;/code&gt; statement&lt;/a&gt; into an interactive &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python REPL&lt;/a&gt;, then you’ll be presented with the nineteen aphorisms that make up the Zen of Python:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;this&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;The Zen of Python, by Tim Peters&lt;/span&gt;

&lt;span class=&quot;go&quot;&gt;Beautiful is better than ugly.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Explicit is better than implicit.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Simple is better than complex.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Complex is better than complicated.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Flat is better than nested.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Sparse is better than dense.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Readability counts.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Special cases aren&#x27;t special enough to break the rules.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Although practicality beats purity.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Errors should never pass silently.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Unless explicitly silenced.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;In the face of ambiguity, refuse the temptation to guess.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;There should be one-- and preferably only one --obvious way to do it.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Although that way may not be obvious at first unless you&#x27;re Dutch.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Now is better than never.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Although never is often better than *right* now.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;If the implementation is hard to explain, it&#x27;s a bad idea.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;If the implementation is easy to explain, it may be a good idea.&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Namespaces are one honking great idea -- let&#x27;s do more of those!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The byline reveals the poem’s author, &lt;a href=&quot;https://en.wikipedia.org/wiki/Tim_Peters_(software_engineer)&quot;&gt;Tim Peters&lt;/a&gt;, who’s a renowned software engineer and a long-standing &lt;a href=&quot;https://realpython.com/cpython-source-code-guide/&quot;&gt;CPython&lt;/a&gt; core developer best known for inventing the &lt;a href=&quot;https://realpython.com/sorting-algorithms-python/#the-timsort-algorithm-in-python&quot;&gt;Timsort&lt;/a&gt; sorting algorithm. He also authored the &lt;a href=&quot;https://realpython.com/python-doctest/&quot;&gt;&lt;code&gt;doctest&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-timer/#estimating-running-time-with-timeit&quot;&gt;&lt;code&gt;timeit&lt;/code&gt;&lt;/a&gt; modules in the Python standard library, along with making many other contributions.&lt;/p&gt;
&lt;p&gt;Take your time to read through the Zen of Python and contemplate its wisdom. But don’t take the aphorisms literally, as they’re more of a guiding set of principles rather than strict instructions. You’ll learn about their humorous origins in the next section.&lt;/p&gt;
&lt;h2 id=&quot;how-did-the-zen-of-python-originate&quot;&gt;How Did the Zen of Python Originate?&lt;a class=&quot;headerlink&quot; href=&quot;#how-did-the-zen-of-python-originate&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The idea of formulating a single document that would encapsulate Python’s fundamental philosophies emerged among the core developers in June 1999. As more and more people began coming to Python from other programming languages, they’d often bring their preconceived notions of software design that weren’t necessarily &lt;a href=&quot;https://realpython.com/learning-paths/writing-pythonic-code/&quot;&gt;Pythonic&lt;/a&gt;. To help them follow the spirit of the language, a set of recommendations for writing idiomatic Python was needed.&lt;/p&gt;
&lt;p&gt;The initial discussion about creating such a document took place on the Python mailing list under the subject &lt;em&gt;The Python Way&lt;/em&gt;. Today, you can find this conversation in the official &lt;a href=&quot;https://mail.python.org/pipermail/python-list/1999-June/subject.html&quot;&gt;Python-list archive&lt;/a&gt;. If you look closely at the &lt;a href=&quot;https://mail.python.org/pipermail/python-list/1999-June/001951.html&quot;&gt;first message from Tim Peters&lt;/a&gt; in that thread, then you’ll notice that he clearly outlined the Zen of Python as a joke. That original form has stuck around until this day:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Clearly a job for Guido alone – although I doubt it’s one he’ll take on
(fwiw, I wish he would too!).  Here’s the outline he would start from,
though &amp;lt;wink&amp;gt;:&lt;/p&gt;
&lt;p&gt;Beautiful is better than ugly.&lt;br&gt;
Explicit is better than implicit.&lt;br&gt;
Simple is better than complex.&lt;br&gt;
Complex is better than complicated.&lt;br&gt;
Flat is better than nested.&lt;br&gt;
Sparse is better than dense.&lt;br&gt;
Readability counts.&lt;br&gt;
Special cases aren’t special enough to break the rules.&lt;br&gt;
Although practicality beats purity.&lt;br&gt;
Errors should never pass silently.&lt;br&gt;
Unless explicitly silenced.&lt;br&gt;
In the face of ambiguity, refuse the temptation to guess.&lt;br&gt;
There should be one– and preferably only one –obvious way to do it.&lt;br&gt;
Although that way may not be obvious at first unless you’re Dutch.&lt;br&gt;
Now is better than never.&lt;br&gt;
Although never is often better than &lt;em&gt;right&lt;/em&gt; now.&lt;br&gt;
If the implementation is hard to explain, it’s a bad idea.&lt;br&gt;
If the implementation is easy to explain, it may be a good idea.&lt;br&gt;
Namespaces are one honking great idea – let’s do more of those!&lt;/p&gt;
&lt;p&gt;There you go:  20 Pythonic Fec^H^H^HTheses on the nose, counting the one I’m
leaving for Guido to fill in.  If the answer to &lt;em&gt;any&lt;/em&gt; Python design issue
isn’t obvious after reading those – well, I just give up &amp;lt;wink&amp;gt;. (&lt;a href=&quot;https://mail.python.org/pipermail/python-list/1999-June/001951.html&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The wink and the playful way of self-censoring some &lt;a href=&quot;https://en.wikipedia.org/wiki/Toilet_humour&quot;&gt;toilet humor&lt;/a&gt; are clear giveaways that Tim Peters didn’t want anyone to take his comment too seriously.&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 case you didn’t get the joke, he started to write something like &lt;em&gt;Feces&lt;/em&gt; but then used &lt;code&gt;^H&lt;/code&gt;—which represents a &lt;span class=&quot;keys&quot;&gt;&lt;kbd class=&quot;key-backspace&quot;&gt;Backspace&lt;/kbd&gt;&lt;/span&gt; in older text editors like &lt;a href=&quot;https://realpython.com/vim-and-python-a-match-made-in-heaven/&quot;&gt;Vim&lt;/a&gt;—to delete the last three letters and make the word &lt;em&gt;Theses&lt;/em&gt;. Therefore, the intended phrase is &lt;em&gt;20 Pythonic Theses&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Eventually, these nearly twenty theses got a proper name and were formally codified in a &lt;a href=&quot;https://peps.python.org/pep-0001/&quot;&gt;Python Enhancement Proposal&lt;/a&gt; document. Each PEP document receives a number. For example, you might have stumbled on &lt;a href=&quot;https://realpython.com/python-pep8/&quot;&gt;PEP 8&lt;/a&gt;, which is the style guide for writing readable Python code. Perhaps as an inside joke, the Zen of Python received the number &lt;a href=&quot;https://peps.python.org/pep-0020/&quot;&gt;PEP 20&lt;/a&gt; to signify the incomplete number of aphorisms in it.&lt;/p&gt;
&lt;p&gt;To win your next argument about what makes good Python code, you can back up your claims with the Zen of Python. If you’d like to refer to a specific aphorism instead of the entire poem, then consider visiting &lt;a href=&quot;https://pep20.org/&quot;&gt;pep20.org&lt;/a&gt;, which provides convenient clickable links to each principle.&lt;/p&gt;
&lt;p&gt;And, in case you want to learn the poem by heart while having some fun, you can now listen to a &lt;a href=&quot;https://www.youtube.com/watch?v=i6G6dmVJy74&quot;&gt;song&lt;/a&gt; with the Zen of Python as its lyrics. &lt;a href=&quot;https://twitter.com/pumpichank&quot;&gt;Barry Warsaw&lt;/a&gt;, another core developer involved with Python since its early days, composed and performed this musical rendition. The song became the closing track on a special vinyl record entitled &lt;a href=&quot;https://www.edgedb.com/blog/the-zen-side-of-the-moon&quot;&gt;&lt;em&gt;The Zen Side of the Moon&lt;/em&gt;&lt;/a&gt;, which was &lt;a href=&quot;https://twitter.com/pyladies/status/1649988104433061888&quot;&gt;auctioned&lt;/a&gt; at &lt;a href=&quot;https://realpython.com/python-news-april-2023/#pycon-us-2023-celebrates-its-twentieth-anniversary&quot;&gt;PyCon US 2023&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Okay. Now that you have a rough idea of what the Zen of Python is and how it came about, you might be asking yourself whether you should really follow it.&lt;/p&gt;
&lt;h2 id=&quot;should-you-obey-the-zen-of-python&quot;&gt;Should You Obey the Zen of Python?&lt;a class=&quot;headerlink&quot; href=&quot;#should-you-obey-the-zen-of-python&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/zen-of-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/zen-of-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>Mazes in Python Part 1: Building and Visualizing</title>
      <id>https://realpython.com/courses/python-maze-solver-part-1/</id>
      <link href="https://realpython.com/courses/python-maze-solver-part-1/"/>
      <updated>2023-06-06T14:00:00+00:00</updated>
      <summary>In part one of this two-part project, you&#x27;ll design your maze and represent it in an object-oriented way. You&#x27;ll also visualize the maze and its solution using scalable vector graphics (SVG).</summary>
      <content type="html">
        &lt;p&gt;If you&amp;rsquo;re up for a little challenge and would like to take your programming skills to the next level, then you&amp;rsquo;ve come to the right place! In this hands-on video course, you&amp;rsquo;ll practice object-oriented programming, among several other good practices, while building a cool maze solver project in Python.&lt;/p&gt;
&lt;p&gt;This is the first part in a two-part series. Throughout the series, you&amp;rsquo;ll go step by step through the guided process of building a complete and working project. This will include reading a maze from a binary file, visualizing it using scalable vector graphics (SVG), and finding the shortest path from the entrance to the exit.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In part one of the series, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use an &lt;strong&gt;object-oriented approach&lt;/strong&gt; to represent the maze in memory&lt;/li&gt;
&lt;li&gt;Visualize the maze and its solution using &lt;strong&gt;scalable vector graphics (SVG)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the next part of the series, you&amp;rsquo;ll complete the project by creating a binary storage format for mazes and solving mazes using NetworkX.&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 NumPy Random Number Generator</title>
      <id>https://realpython.com/numpy-random-number-generator/</id>
      <link href="https://realpython.com/numpy-random-number-generator/"/>
      <updated>2023-06-05T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll take a look at the powerful random number capabilities of the NumPy random number generator. You&#x27;ll learn how to work with both individual numbers and NumPy arrays, as well as how to sample from a statistical distribution.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;&lt;strong&gt;Random numbers&lt;/strong&gt; are a very useful feature in many different types of programs, from mathematics and data analysis through to computer games and encryption applications. You may be surprised to learn that it’s actually quite difficult to get a computer to generate true randomness. However, if you’re careful, the NumPy random number generator can generate random enough numbers for everyday purposes.&lt;/p&gt;
&lt;p&gt;Maybe you’ve already worked with &lt;a href=&quot;https://realpython.com/python-random/&quot;&gt;randomly generated data in Python&lt;/a&gt;. While modules like &lt;a href=&quot;https://docs.python.org/3/library/random.html#random.Random&quot;&gt;&lt;code&gt;random&lt;/code&gt;&lt;/a&gt; are great options for producing random scalars, using the &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/index.html&quot;&gt;&lt;code&gt;numpy.random&lt;/code&gt;&lt;/a&gt; module will unlock even more possibilities for you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Generate NumPy arrays&lt;/strong&gt; of random numbers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Randomize&lt;/strong&gt; NumPy arrays&lt;/li&gt;
&lt;li&gt;Randomly &lt;strong&gt;select parts&lt;/strong&gt; of NumPy arrays&lt;/li&gt;
&lt;li&gt;Take random samples from &lt;strong&gt;statistical distributions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before starting this tutorial, you should understand the basics of &lt;a href=&quot;https://realpython.com/numpy-tutorial/&quot;&gt;NumPy arrays&lt;/a&gt;. With that knowledge, you’re ready to dive in.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/numpy-random-number-generator-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-numpy-random-number-generator-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the sample code&lt;/a&gt; that shows you how to get random numbers with NumPy.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;understanding-the-numpy-pseudo-random-number-generator&quot;&gt;Understanding the NumPy Pseudo-Random Number Generator&lt;a class=&quot;headerlink&quot; href=&quot;#understanding-the-numpy-pseudo-random-number-generator&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;When you ask a computer to perform any task for you, it does so by following a set of instructions defined by an algorithm. When you need it to generate random numbers, the computer uses a &lt;a href=&quot;https://en.wikipedia.org/wiki/Pseudorandom_number_generator&quot;&gt;pseudo-random number generator&lt;/a&gt; (PRNG) algorithm. There are several of these available, some of which are better than others.&lt;/p&gt;
&lt;p&gt;To generate random numbers, Python uses the &lt;a href=&quot;https://docs.python.org/3/library/random.html&quot;&gt;&lt;code&gt;random&lt;/code&gt; module&lt;/a&gt;, which generates numbers using the &lt;a href=&quot;https://en.wikipedia.org/wiki/Mersenne_Twister&quot;&gt;Mersenne twister algorithm&lt;/a&gt;. While this is still widely used in Python code, it’s possible to predict the numbers that it generates, and it requires significant computing power. &lt;/p&gt;
&lt;p&gt;Since version 1.17, NumPy uses the more efficient &lt;a href=&quot;https://en.wikipedia.org/wiki/Permuted_congruential_generator&quot;&gt;permuted congruential generator-64&lt;/a&gt; (PCG64) algorithm. This produces less-predictable numbers, as shown by its performance in the industry-standard &lt;a href=&quot;https://www.pcg-random.org/statistical-tests.html#&quot;&gt;TestU01 statistical test&lt;/a&gt;. PCG64 is also faster and requires fewer resources to work.&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; While the PCG64 algorithm is certainly an improvement on the Mersenne twister algorithm, it still has some statistical weaknesses. An updated version, &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/bit_generators/pcg64dxsm.html&quot;&gt;PCG64DXSM&lt;/a&gt;, addresses these issues. This will become the default in future NumPy releases. On a practical level, you won’t notice any difference, but if you want to know more, see &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/upgrading-pcg64.html#upgrading-pcg64&quot;&gt;Upgrading &lt;code&gt;PCG64&lt;/code&gt; with &lt;code&gt;PCG64DXSM&lt;/code&gt;&lt;/a&gt; in the NumPy documentation.&lt;/p&gt;
&lt;p&gt;In most of the examples throughout this tutorial, you’ll use the default &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/bit_generators/pcg64.html&quot;&gt;PCG64&lt;/a&gt; algorithm, although you’ll also try your hand at using the updated PCG64DXSM algorithm.&lt;/p&gt;
&lt;p&gt;If you’re interested in learning more about the different types of PRNG algorithms and how the PCG algorithms compare to others, then you should read &lt;a href=&quot;https://www.pcg-random.org/&quot;&gt;PCG, A Family of Better Random Number Generators&lt;/a&gt; from the developer of PCG.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;PRNGs are called pseudo-random because they’re &lt;em&gt;not&lt;/em&gt; random! PRNGs are &lt;strong&gt;deterministic&lt;/strong&gt;, which means they generate sequences of numbers that are reproducible. PRNGs require a &lt;a href=&quot;https://en.wikipedia.org/wiki/Random_seed&quot;&gt;seed&lt;/a&gt; number to initialize their number generation. PRNGs that use the same seed will generate the same numbers.&lt;/p&gt;
&lt;p&gt;PRNGs also have a &lt;strong&gt;period&lt;/strong&gt; property, which is the number of iterations they go through before they start repeating. Because the generated numbers depend on the seed, they’re not truly random but are instead pseudo-random.&lt;/p&gt;
&lt;p&gt;Because seeds should be random, you need one random number to generate another. For this purpose, PRNGs use the computer hardware clock’s time as their default seed. This is measured to the nanosecond, so running number generators consecutively results in different seed values and therefore different sequences of random numbers. NumPy uses a &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/bit_generators/index.html#seeding-and-entropy&quot;&gt;hashing technique&lt;/a&gt; to ensure that the seed is 128 bits long, even if you only supply a 64-bit integer.&lt;/p&gt;
&lt;p&gt;The period does mean that the same numbers could reappear. In practice, this isn’t a concern because the period lengths are huge. &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/bit_generators/pcg64.html&quot;&gt;The period of PCG64&lt;/a&gt;, for example, is about 50 billion times the number of atoms that exist inside of you!&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 want to learn more about how random randomly generated numbers actually are, take a look at the tutorial &lt;a href=&quot;https://realpython.com/python-random/#how-random-is-random&quot;&gt;How Random is Random?&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The core of NumPy’s number generation is the &lt;strong&gt;&lt;code&gt;BitGenerator&lt;/code&gt;&lt;/strong&gt; class. This class allows you to specify an algorithm and seed. To access the random numbers, the &lt;code&gt;BitGenerator&lt;/code&gt; is passed into a separate &lt;strong&gt;&lt;code&gt;Generator&lt;/code&gt;&lt;/strong&gt; object. Generators have methods that allow you to access a range of random numbers and perform several randomizing operations. The &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/index.html&quot;&gt;&lt;code&gt;numpy.random&lt;/code&gt;&lt;/a&gt; module provides this capability.&lt;/p&gt;
&lt;p&gt;You may have noticed that the &lt;code&gt;NumPy.random&lt;/code&gt; documentation also contains information about the &lt;a href=&quot;https://numpy.org/doc/stable/reference/random/legacy.html#numpy.random.RandomState&quot;&gt;&lt;code&gt;RandomState&lt;/code&gt;&lt;/a&gt; class. This is a container class for the slower Mersenne twister PRNG. The more modern &lt;code&gt;Generator&lt;/code&gt; class has now superseded &lt;code&gt;RandomState&lt;/code&gt;, which you should no longer use in new code. However, &lt;code&gt;RandomState&lt;/code&gt; is still around for existing legacy applications. &lt;/p&gt;
&lt;p&gt;Before you go any further, be aware that the NumPy PRNGs are &lt;em&gt;not&lt;/em&gt; suitable for cryptographic purposes. They’re only suitable for data analysis tasks. If you need random numbers for cryptographic purposes, then you need a &lt;a href=&quot;https://realpython.com/python-random/#csprngs-in-python&quot;&gt;cryptographically secure pseudo-random number generator (CSPRNG)&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;generating-random-data-with-the-numpy-random-number-generator&quot;&gt;Generating Random Data With the NumPy Random Number Generator&lt;a class=&quot;headerlink&quot; href=&quot;#generating-random-data-with-the-numpy-random-number-generator&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Now that you understand a computer’s capabilities for generating random numbers, in this section, you’ll learn how to generate both floating-point numbers and integers randomly using NumPy. After generating individual numbers, you’ll learn how to generate NumPy arrays of random numbers.&lt;/p&gt;
&lt;h3 id=&quot;random-numbers&quot;&gt;Random Numbers&lt;a class=&quot;headerlink&quot; href=&quot;#random-numbers&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you’re happy to let NumPy perform all of your random number generation work for you, you can use its default values. In other words, your &lt;code&gt;BitGenerator&lt;/code&gt; will use PCG64 with a seed from the computer’s clock. To facilitate the defaults, NumPy provides a very handy &lt;strong&gt;&lt;code&gt;default_rng()&lt;/code&gt;&lt;/strong&gt; function. This sets everything up for you and returns a reference to a &lt;code&gt;Generator&lt;/code&gt; object for you to use to produce random numbers using its range of powerful methods.&lt;/p&gt;
&lt;p&gt;To begin with, this code generates a floating-point number using NumPy’s defaults:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;np&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;default_rng&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;default_rng&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;default_rng&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;Generator(PCG64) at 0x1E9F2ABBF20&#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;default_rng&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0.47418635476614734&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/numpy-random-number-generator/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/numpy-random-number-generator/ »&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 #158: Building Python CI With Docker &amp; Applying for a Hacker Initiative Grant</title>
      <id>https://realpython.com/podcasts/rpp/158/</id>
      <link href="https://realpython.com/podcasts/rpp/158/"/>
      <updated>2023-06-02T12:00:00+00:00</updated>
      <summary>Do you need a refresher on using Docker with Python? Would you like to learn how to configure a continuous integration pipeline with modern tools and Docker? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;Do you need a refresher on using Docker with Python? Would you like to learn how to configure a continuous integration pipeline with modern tools and Docker? This week on the show, Christopher Trudeau is here, 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>Create and Modify PDF Files in Python</title>
      <id>https://realpython.com/creating-modifying-pdf/</id>
      <link href="https://realpython.com/creating-modifying-pdf/"/>
      <updated>2023-05-31T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll explore the different ways of creating and modifying PDF files in Python. You&#x27;ll learn how to read and extract text, merge and concatenate files, crop and rotate pages, encrypt and decrypt files, and even create PDFs from scratch.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;It’s really useful to know how to create and modify &lt;a href=&quot;https://en.wikipedia.org/wiki/PDF&quot;&gt;PDF (portable document format)&lt;/a&gt; files in Python. This is one of the most common formats for sharing documents over the Internet. &lt;a href=&quot;https://realpython.com/pdf-python/&quot;&gt;PDF files&lt;/a&gt; can contain text, images, tables, forms, and rich media like videos and animations, all in a single file.&lt;/p&gt;
&lt;p&gt;This abundance of content types can make working with PDFs difficult. There are several different kinds of data to decode when opening a PDF file! Fortunately, the Python ecosystem has some great packages for reading, manipulating, and creating PDF files.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Read&lt;/strong&gt; text from a PDF with &lt;code&gt;pypdf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Split&lt;/strong&gt; a PDF file into multiple files&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concatenate&lt;/strong&gt; and &lt;strong&gt;merge&lt;/strong&gt; PDF files together&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rotate&lt;/strong&gt; and &lt;strong&gt;crop&lt;/strong&gt; pages in PDF files&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Encrypt&lt;/strong&gt; and &lt;strong&gt;decrypt&lt;/strong&gt; PDF files&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create&lt;/strong&gt; and &lt;strong&gt;customize&lt;/strong&gt; PDF files from scratch with ReportLab&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To complete this learning, you’ll use two different tools. You’ll use the &lt;a href=&quot;https://pypdf.readthedocs.io/en/stable/index.html&quot;&gt;&lt;code&gt;pypdf&lt;/code&gt;&lt;/a&gt; library to manipulate existing PDF files and the &lt;a href=&quot;https://docs.reportlab.com/&quot;&gt;ReportLab&lt;/a&gt; library to create new PDF files from scratch. Along the way, you’ll have several opportunities to deepen your understanding with exercises and examples.&lt;/p&gt;
&lt;p&gt;To follow along with this tutorial, you should download and extract to your home folder the materials used in the examples. To do this, click the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Download the sample materials:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/create-modify-pdf/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-create-modify-pdf&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to get the materials you’ll use&lt;/a&gt; to learn about creating and modifying PDF files in this tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;extracting-text-from-pdf-files-with-pypdf&quot;&gt;Extracting Text From PDF Files With &lt;code&gt;pypdf&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#extracting-text-from-pdf-files-with-pypdf&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In this section, you’ll learn how to read PDF files and extract their text using the &lt;a href=&quot;https://pypi.org/project/pypdf/&quot;&gt;&lt;code&gt;pypdf&lt;/code&gt;&lt;/a&gt; library. Before you can do that, though, you need to install it with &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;&lt;code&gt;pip&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight sh&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 -m pip install pypdf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With this command, you download and install the latest version of &lt;code&gt;pypdf&lt;/code&gt; from the Python package index (&lt;a href=&quot;https://realpython.com/pypi-publish-python-package/&quot;&gt;PyPI&lt;/a&gt;). To verify the installation, go ahead and run the following command in your &lt;a href=&quot;https://realpython.com/terminal-commands/&quot;&gt;terminal&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight sh&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 -m pip show pypdf
&lt;span class=&quot;go&quot;&gt;Name: pypdf&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;go&quot;&gt;Version: 3.8.1&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;Summary: A pure-python PDF library capable of splitting,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; merging, cropping, and transforming PDF files&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Home-page:&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Author:&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Author-email: Mathieu Fenniak &amp;lt;biziqe@mathieu.fenniak.net&amp;gt;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;License:&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Location: .../lib/python3.10/site-packages&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Requires:&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Required-by:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Pay particular attention to the version information. At the time of publication for this tutorial, the latest version of &lt;code&gt;pypdf&lt;/code&gt; was &lt;code&gt;3.8.1&lt;/code&gt;. This library has gotten plenty of updates lately, and cool new features are added quite frequently. Most importantly, you’ll find many breaking changes in the library’s API if you compare it with its predecessor library &lt;a href=&quot;https://pypdf.readthedocs.io/en/stable/meta/history.html#pypdf2-is-born-2011-2016&quot;&gt;&lt;code&gt;PyPDF2&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Before diving into working with PDF files, you must know that this tutorial is adapted from the chapter “Creating and Modifying PDF Files” in &lt;a href=&quot;https://realpython.com/products/python-basics-book/&quot;&gt;&lt;em&gt;Python Basics: A Practical Introduction to Python 3&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The book uses Python’s built-in &lt;a href=&quot;https://realpython.com/python-idle/&quot;&gt;IDLE&lt;/a&gt; editor to create and edit Python files and interact with the Python shell, so you’ll find occasional references to IDLE throughout this tutorial. However, you should have no problems running the example code from the &lt;a href=&quot;https://realpython.com/python-ides-code-editors-guide/&quot;&gt;editor&lt;/a&gt; and environment of your choice.&lt;/p&gt;
&lt;h3 id=&quot;reading-pdf-files-with-pdfreader&quot;&gt;Reading PDF Files With &lt;code&gt;PdfReader&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#reading-pdf-files-with-pdfreader&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To kick things off, you’ll open a PDF file and read some information about it. You’ll use the &lt;code&gt;Pride_and_Prejudice.pdf&lt;/code&gt; file provided in the downloadable resources for this tutorial.&lt;/p&gt;
&lt;p&gt;Open IDLE’s interactive window and &lt;a href=&quot;https://realpython.com/python-import/&quot;&gt;import&lt;/a&gt; the &lt;code&gt;PdfReader&lt;/code&gt; class from &lt;code&gt;pypdf&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;nn&quot;&gt;pypdf&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PdfReader&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To create a new instance of the &lt;code&gt;PdfReader&lt;/code&gt; class, you’ll need to provide the &lt;a href=&quot;https://realpython.com/read-write-files-python/#file-paths&quot;&gt;path&lt;/a&gt; to the PDF file that you want to open. You can do that using the &lt;a href=&quot;https://realpython.com/python-pathlib/&quot;&gt;&lt;code&gt;pathlib&lt;/code&gt;&lt;/a&gt; module:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;nn&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&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;pdf_path&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;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;home&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;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;creating-and-modifying-pdfs&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;practice_files&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Pride_and_Prejudice.pdf&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;pdf_path&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt; now contains the path to a PDF version of Jane Austen’s &lt;em&gt;Pride and Prejudice&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may need to change &lt;code&gt;pdf_path&lt;/code&gt; so that it corresponds to the location of the &lt;code&gt;creating-and-modifying-pdfs/&lt;/code&gt; folder on your computer.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now create the &lt;code&gt;PdfReader&lt;/code&gt; instance by calling the class’s &lt;a href=&quot;https://realpython.com/python-class-constructor/&quot;&gt;constructor&lt;/a&gt; with the path to your PDF file as an argument:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;pdf_reader&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PdfReader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pdf_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/creating-modifying-pdf/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/creating-modifying-pdf/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Getting the First Match From a Python List or Iterable</title>
      <id>https://realpython.com/courses/python-first-match/</id>
      <link href="https://realpython.com/courses/python-first-match/"/>
      <updated>2023-05-30T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn about the best ways to get the first match from a Python list or iterable. You&#x27;ll look into two different strategies, for loops and generators, and compare their performance. Then you&#x27;ll finish up by creating a reusable function for all your first matching needs.</summary>
      <content type="html">
        &lt;p&gt;At some point in your Python journey, you may need to find the &lt;strong&gt;first item that matches a certain criterion&lt;/strong&gt; in a Python &lt;a href=&quot;https://realpython.com/python-for-loop/#iterables&quot;&gt;iterable&lt;/a&gt;, such as a &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;list&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The simplest case is that you need to confirm that a particular item exists in the iterable. For example, you want to find a name in a list of names or a &lt;a href=&quot;https://realpython.com/python-string-contains-substring/&quot;&gt;substring inside a string&lt;/a&gt;. In these cases, you&amp;rsquo;re best off using the &lt;code&gt;in&lt;/code&gt; operator. However, there are many use cases when you may want to look for items with specific properties. For instance, you may need to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Find a non-zero value in a list of &lt;a href=&quot;https://realpython.com/python-numbers/&quot;&gt;numbers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Find a name of a particular length in a list of &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;strings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Find and modify a dictionary in a list of dictionaries based on a certain attribute&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll explore how best to approach all three scenarios.&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>Choosing the Best Coding Font for Programming</title>
      <id>https://realpython.com/coding-font/</id>
      <link href="https://realpython.com/coding-font/"/>
      <updated>2023-05-29T14:00:00+00:00</updated>
      <summary>The font that you use is an important piece in your tool kit as a programmer. After all, you look at your programming font the whole time when writing code. In this tutorial, you&#x27;ll find your perfect font for coding.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;When you’re coding, there’s always a font involved in displaying the text on the screen. Yet, the font that you use is an often-overlooked piece in your programming tool kit. Many operating systems and code editors come with their default monospace fonts that you may end up using.&lt;/p&gt;
&lt;p&gt;But there are a bunch of technicalities and features to take into consideration when choosing the best font for your daily programming. That’s why it’s worth investigating the requirements that a &lt;strong&gt;programming font&lt;/strong&gt; should fulfill to make it a perfect match for you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to spot a &lt;strong&gt;high-quality&lt;/strong&gt; coding font&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;characters&lt;/strong&gt; are important when coding in Python&lt;/li&gt;
&lt;li&gt;Which &lt;strong&gt;features&lt;/strong&gt; of a programming font matter&lt;/li&gt;
&lt;li&gt;Where to &lt;strong&gt;download&lt;/strong&gt; programming fonts&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;install&lt;/strong&gt; a font on your operating system&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Throughout the tutorial, you’ll consider twenty-seven hand-picked programming fonts that you can use right away.
You’ll take a close look at all the fonts and investigate why their particular features are important for you as a programmer.
In the end, you’ll be able to decide which coding fonts suit your needs best.&lt;/p&gt;
&lt;p&gt;If you want to keep a list of the fonts for future reference, then you can get an overview PDF of all the fonts by clicking the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/coding-font-guide/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-coding-font-guide&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download your comprehensive guide&lt;/a&gt; to all the coding fonts in this tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;say-hello-to-your-next-coding-font&quot;&gt;Say Hello to Your Next Coding Font&lt;a class=&quot;headerlink&quot; href=&quot;#say-hello-to-your-next-coding-font&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In this tutorial, you’ll take a deep dive and learn about the forms and shapes that make a quality coding font.
You’ll encounter significant technical details, handy features, and surprising quirks along the way.&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 focus on the characteristics of fonts that are suitable for Python programming. But the fonts will work similarly in any other programming language.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You’ll notice that all the images in this tutorial have a similar style.
The font name is always on the left.
On the right, you’ll see a sample string or specific characters worth noting. To kick things off, have a look at the fonts that you’ll examine in this tutorial:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/font-list.684fdef10e95.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/font-list.684fdef10e95.png&quot; width=&quot;1344&quot; height=&quot;1920&quot; srcset=&quot;https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/font-list.684fdef10e95.png&amp;amp;w=336&amp;amp;sig=e4f27e4d87d2ab6ae30eb990ddd35b52f36d2356 336w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/font-list.684fdef10e95.png&amp;amp;w=448&amp;amp;sig=e487e11ca39420a07fa0d4bd4dd442f55b4fcc0f 448w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/font-list.684fdef10e95.png&amp;amp;w=672&amp;amp;sig=23d61fc97853c497318ded816e86092e3b2f735e 672w, https://files.realpython.com/media/font-list.684fdef10e95.png 1344w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&#x27;Screenshot of all fonts showing a &quot;Hello, World!&quot; string&#x27; data-asset=&quot;5147&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;It’s a good idea to open this image in another window and keep it open while you read the tutorial.
For example, you can right-click the image above, select &lt;em&gt;Open Image in New Window&lt;/em&gt;, and then drag the tab into a new window:&lt;/p&gt;
&lt;figure&gt;
  &lt;div class=&quot;embed-responsive embed-responsive-16by9 rounded mb-3 border&quot;&gt;
    &lt;iframe loading=&quot;lazy&quot; class=&quot;embed-responsive-item&quot; src=&quot;https://player.vimeo.com/video/829906974?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;Having the tutorial and the fonts list side by side lets you conveniently compare certain fonts with others. You can even go a step further and print the image to annotate the fonts with your likes and dislikes.&lt;/p&gt;
&lt;p&gt;If you’re already excited to try out new fonts in your own coding editor, then you can scroll down to the &lt;a href=&quot;#get-your-new-coding-font&quot;&gt;get your new coding font&lt;/a&gt; section.
There you can download all the fonts in this tutorial and load them up in your editor.
That way, you can get a head start and evaluate any font with your own editor theme, preferred font size, and some familiar code.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Color schemes and font sizes are very personal settings that can easily skew your evaluation of a font.
That’s why you won’t see any larger code samples set in any font in this tutorial.&lt;/p&gt;
&lt;p&gt;Instead, you’ll see many examples that objectively focus on specific font characteristics, independently of any coding editors.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Once you try out a coding font, you’ll recognize if you like or dislike it.
Sometimes it’s just a matter of taste.
But sometimes there are reasons why one font might be a better fit for you while another isn’t.&lt;/p&gt;
&lt;p&gt;Over the next few sections, you’ll get a tool set so that you can evaluate for yourself what makes a quality programming font.&lt;/p&gt;
&lt;h2 id=&quot;consider-the-basics&quot;&gt;Consider the Basics&lt;a class=&quot;headerlink&quot; href=&quot;#consider-the-basics&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Whether you just wrote your first &lt;a href=&quot;https://en.wikipedia.org/wiki/%22Hello,_World!%22_program&quot;&gt;&lt;code&gt;Hello, World!&lt;/code&gt;&lt;/a&gt; script or maintain huge codebases, choosing the right programming font will be beneficial for you as a developer.&lt;/p&gt;
&lt;p&gt;Before you dig into the characteristics of a font on a character level, there are some broader features to take into consideration. Some of them may filter out a font in your search from the get-go.&lt;/p&gt;
&lt;p&gt;For example, a font might not be a good choice if the font doesn’t support your language or if it costs money that you’re not willing to invest. Another criterion could be that the font must be monospace.&lt;/p&gt;
&lt;p&gt;In this section, you’ll explore important points of comparison.
That way, you’ll know which fonts to include in your circle of coding fonts to consider more closely.&lt;/p&gt;
&lt;h3 id=&quot;does-the-font-file-format-matter&quot;&gt;Does the Font File Format Matter?&lt;a class=&quot;headerlink&quot; href=&quot;#does-the-font-file-format-matter&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/coding-font/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/coding-font/ »&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 #157: Discussing Mojo &amp; Improving Python Object-Oriented Programming</title>
      <id>https://realpython.com/podcasts/rpp/157/</id>
      <link href="https://realpython.com/podcasts/rpp/157/"/>
      <updated>2023-05-26T12:00:00+00:00</updated>
      <summary>Would you like to speed up your Python machine-learning code dramatically? What if you only had to change a few keywords and add a couple of type hints on portions of your code? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;Would you like to speed up your Python machine-learning code dramatically? What if you only had to change a few keywords and add a couple of type hints on portions of your code? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python&#x27;s .__call__() Method: Creating Callable Instances</title>
      <id>https://realpython.com/python-callable-instances/</id>
      <link href="https://realpython.com/python-callable-instances/"/>
      <updated>2023-05-24T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn what a callable is in Python and how to create callable instances using the .__call__() special method in your custom classes. You&#x27;ll also code several examples of practical use cases for callable instances in Python.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In Python, a &lt;strong&gt;callable&lt;/strong&gt; is any object that you can call using a pair of parentheses and, optionally, a series of arguments. Functions, classes, and methods are all common examples of callables in Python. Besides these, you can also create custom classes that produce &lt;strong&gt;callable instances&lt;/strong&gt;. To do this, you can add the &lt;strong&gt;&lt;code&gt;.__call__()&lt;/code&gt;&lt;/strong&gt; special method to your class.&lt;/p&gt;
&lt;p&gt;Instances of a class with a &lt;code&gt;.__call__()&lt;/code&gt; method behave like functions, providing a flexible and handy way to add functionality to your objects. Understanding how to create and use callable instances is a valuable skill for you as a Python developer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Understand the concept of &lt;strong&gt;callable objects&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;callable instances&lt;/strong&gt; by providing your classes with a &lt;strong&gt;&lt;code&gt;.__call__()&lt;/code&gt;&lt;/strong&gt; method&lt;/li&gt;
&lt;li&gt;Understand the &lt;strong&gt;difference&lt;/strong&gt; between &lt;strong&gt;&lt;code&gt;.__init__()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;.__call__()&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Code several examples of using callable instances to solve &lt;strong&gt;real-world problems&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should be comfortable with the basics of &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented&lt;/a&gt; programming in Python, including how to define and use &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt; and methods. Some familiarity with Python &lt;a href=&quot;https://realpython.com/primer-on-python-decorators/&quot;&gt;decorators&lt;/a&gt; and the &lt;a href=&quot;https://en.wikipedia.org/wiki/Strategy_pattern&quot;&gt;strategy design pattern&lt;/a&gt; will also help. You should also understand the concept of &lt;a href=&quot;https://en.wikipedia.org/wiki/State_(computer_science)&quot;&gt;state&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-callable-instances-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-callable-instances-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download your sample code&lt;/a&gt; so that you can create callable instances with Python’s &lt;code&gt;.__call__()&lt;/code&gt; method.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;understanding-callable-objects-in-python&quot;&gt;Understanding Callable Objects in Python&lt;a class=&quot;headerlink&quot; href=&quot;#understanding-callable-objects-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-callable&quot;&gt;callable&lt;/a&gt; in Python is any object that you can call using a pair of parentheses and a series of arguments if required. You’ll find different examples of callables in your daily interaction with Python. Some of them include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/3/library/functions.html&quot;&gt;Built-in&lt;/a&gt; functions and classes&lt;/li&gt;
&lt;li&gt;User-defined &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt; that you create with the &lt;a href=&quot;https://realpython.com/python-keywords/#the-def-keyword&quot;&gt;&lt;code&gt;def&lt;/code&gt;&lt;/a&gt; keyword&lt;/li&gt;
&lt;li&gt;Anonymous functions that you write using the &lt;a href=&quot;https://realpython.com/python-lambda/&quot;&gt;&lt;code&gt;lambda&lt;/code&gt;&lt;/a&gt; keyword&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://realpython.com/python-class-constructor/&quot;&gt;constructors&lt;/a&gt; of your custom &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-classes/#instance-methods-with-self&quot;&gt;Instance&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-classes/#class-methods-with-classmethod&quot;&gt;class&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-classes/#static-methods-with-staticmethod&quot;&gt;static&lt;/a&gt; methods&lt;/li&gt;
&lt;li&gt;Instances of classes that implement the &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html#object.__call__&quot;&gt;&lt;code&gt;.__call__()&lt;/code&gt;&lt;/a&gt; method&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/inner-functions-what-are-they-good-for/#retaining-state-with-inner-functions-closures&quot;&gt;Closures&lt;/a&gt; that you return from your functions&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/introduction-to-python-generators/&quot;&gt;Generator&lt;/a&gt; functions that you define using the &lt;a href=&quot;https://realpython.com/introduction-to-python-generators/#understanding-the-python-yield-statement&quot;&gt;&lt;code&gt;yield&lt;/code&gt;&lt;/a&gt; keyword&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-async-features/&quot;&gt;Asynchronous&lt;/a&gt; functions and methods that you create with the &lt;a href=&quot;https://realpython.com/python-keywords/#the-async-keyword&quot;&gt;&lt;code&gt;async&lt;/code&gt;&lt;/a&gt; keyword&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All these different callables have something in common. They all implement the &lt;code&gt;.__call__()&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-classes/#special-methods-and-protocols&quot;&gt;special method&lt;/a&gt;. To confirm this fact, you can use the built-in &lt;a href=&quot;https://realpython.com/python-scope-legb-rule/#dir&quot;&gt;&lt;code&gt;dir()&lt;/code&gt;&lt;/a&gt; function, which takes an object as an argument and &lt;a href=&quot;https://realpython.com/python-return-statement/&quot;&gt;returns&lt;/a&gt; the object’s list of attributes and methods:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__call__&#x27;,&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__class__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    ...&lt;/span&gt;
&lt;span class=&quot;go&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;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__call__&#x27;,&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__class__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    ...&lt;/span&gt;
&lt;span class=&quot;go&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;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;greet&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, World!&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;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__annotations__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__builtins__&#x27;,&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__call__&#x27;,&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;    ...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the first two examples, you call &lt;code&gt;dir()&lt;/code&gt; with the built-in &lt;a href=&quot;https://realpython.com/python-absolute-value/&quot;&gt;&lt;code&gt;abs()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-all/&quot;&gt;&lt;code&gt;all()&lt;/code&gt;&lt;/a&gt; functions as arguments. In both cases, you can see that the &lt;code&gt;.__call__()&lt;/code&gt; method is present in the output.&lt;/p&gt;
&lt;p&gt;In the final example, you define a custom function that &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;prints&lt;/a&gt; a message to the screen. This function also has &lt;code&gt;.__call__()&lt;/code&gt;. Note how you can use this method to call the function:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;greet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;fm&quot;&gt;__call__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Hello, World!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that using &lt;code&gt;.__call__()&lt;/code&gt; as you did in this example produces the same effect as calling the function directly with &lt;code&gt;greet()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Even though you can call special methods like &lt;code&gt;.__call__()&lt;/code&gt; directly, doing so isn’t a recommended or best practice. Instead, call the functions as usual.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now, how does all this work internally? When you run something like &lt;code&gt;callable_object(*args, **kwargs)&lt;/code&gt;, Python internally translates the operation into &lt;code&gt;callable_object.__call__(*args, **kwargs)&lt;/code&gt;. The arguments to the regular function are the same as those used in &lt;code&gt;.__call__()&lt;/code&gt;. In other words, whenever you call a callable object, Python automatically runs its &lt;code&gt;.__call__()&lt;/code&gt; method behind the scenes using the arguments you’ve passed into the callable.&lt;/p&gt;
&lt;p&gt;Now take a look at the following custom class:&lt;/p&gt;
&lt;div class=&quot;highlight python repl&quot;&gt;&lt;span class=&quot;repl-toggle&quot; title=&quot;Toggle REPL prompts and output&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&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;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SampleClass&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;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;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 called method()!&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;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SampleClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;class &#x27;type&#x27;&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;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__abstractmethods__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__annotations__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__base__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__bases__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    &#x27;__basicsize__&#x27;,&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__call__&#x27;,&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;    ...&lt;/span&gt;
&lt;span class=&quot;go&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;sample_instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SampleClass&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;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sample_instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__call__&#x27;,&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;    &#x27;__class__&#x27;,&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    ...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In Python, everything is an object. Classes like &lt;code&gt;SampleClass&lt;/code&gt; are objects of &lt;code&gt;type&lt;/code&gt;, which you can confirm by calling &lt;code&gt;type()&lt;/code&gt; with the class object as an argument or by accessing the &lt;code&gt;.__class__&lt;/code&gt; attribute.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://realpython.com/python-class-constructor/&quot;&gt;class constructor&lt;/a&gt; of &lt;code&gt;SampleClass&lt;/code&gt; falls back to using &lt;code&gt;type.__call__()&lt;/code&gt;. That’s why you can call &lt;code&gt;SampleClass()&lt;/code&gt; to get a new instance. So, class constructors are callable objects that return new instances of the underlying class.&lt;/p&gt;
&lt;p&gt;In the example above, you can observe that method objects, like &lt;code&gt;sample_instance.method&lt;/code&gt;, also have a &lt;code&gt;.__call__()&lt;/code&gt; special method that turns them into callable objects. The main takeaway here is that to be callable, an object needs to have a &lt;code&gt;.__call__()&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;If you inspect a closure, generator function, or asynchronous function, then you’ll get similar results. You’ll always find a &lt;code&gt;.__call__()&lt;/code&gt; method in callable objects.&lt;/p&gt;
&lt;h2 id=&quot;checking-whether-an-object-is-callable&quot;&gt;Checking Whether an Object Is Callable&lt;a class=&quot;headerlink&quot; href=&quot;#checking-whether-an-object-is-callable&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you ever need to check whether a Python object is callable, then you can use the built-in &lt;a href=&quot;https://docs.python.org/3/library/functions.html?highlight=object#callable&quot;&gt;&lt;code&gt;callable()&lt;/code&gt;&lt;/a&gt; function like in the following examples:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-callable-instances/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-callable-instances/ »&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>Using k-Nearest Neighbors (kNN) in Python</title>
      <id>https://realpython.com/courses/knn-python/</id>
      <link href="https://realpython.com/courses/knn-python/"/>
      <updated>2023-05-23T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn all about the k-nearest neighbors (kNN) algorithm in Python, including how to implement kNN from scratch. Once you understand how kNN works, you&#x27;ll use scikit-learn to facilitate your coding process.</summary>
      <content type="html">
        &lt;p&gt;In this video course, you&amp;rsquo;ll get a thorough introduction to the k-Nearest Neighbors (kNN) algorithm in Python. The kNN algorithm is one of the most famous &lt;a href=&quot;https://realpython.com/learning-paths/machine-learning-python/&quot;&gt;machine learning&lt;/a&gt; algorithms and an absolute must-have in your machine learning toolbox. Python is the go-to programming language for machine learning, so what better way to discover kNN than with Python&amp;rsquo;s famous packages &lt;a href=&quot;https://realpython.com/numpy-tutorial/&quot;&gt;NumPy&lt;/a&gt; and &lt;a href=&quot;https://scikit-learn.org/stable/&quot;&gt;scikit-learn&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll explore the kNN algorithm both in theory and in practice. It&amp;rsquo;s important to learn about the mechanics of machine learning algorithms to understand their potential and limitations. At the same time, it&amp;rsquo;s essential to understand how to use an algorithm in practice. With that in mind, you&amp;rsquo;ll also focus on the use of kNN in the Python library scikit-learn.&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;Explain the &lt;strong&gt;kNN algorithm&lt;/strong&gt; both intuitively and mathematically&lt;/li&gt;
&lt;li&gt;Implement kNN in Python &lt;strong&gt;from scratch&lt;/strong&gt; using &lt;strong&gt;NumPy&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use kNN in Python with &lt;strong&gt;scikit-learn&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>Metaclasses in Python</title>
      <id>https://realpython.com/courses/python-metaclasses/</id>
      <link href="https://realpython.com/courses/python-metaclasses/"/>
      <updated>2023-05-16T14:00:00+00:00</updated>
      <summary>Metaclasses are an important but mysterious behind-the-scenes mechanism for instantiating classes in Python. In this video course, you&#x27;ll learn how Python&#x27;s metaclasses work in object-oriented programming.</summary>
      <content type="html">
        &lt;p&gt;In Python, everything is an object, even the classes that create objects. You
used a class to instantiate an object instance, but classes themselves are
also instantiated behind the scenes. This mechanism is available to you as a
programmer through the concept of metaclasses. &lt;/p&gt;
&lt;p&gt;Metaclasses allow you to hook
when classes are created, and this technique is what&amp;rsquo;s behind magical
frameworks like Django and SQLAlchemy where class definitions have side
effects that impact databases.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this course you&amp;rsquo;ll learn about how:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Everything really is an object, including classes themselves&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;type()&lt;/code&gt; function works&lt;/li&gt;
&lt;li&gt;Classes instantiate objects and get instantiated themselves&lt;/li&gt;
&lt;li&gt;You can hook class instantiation with the metaclass argument&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Metaclasses aren&amp;rsquo;t for the faint of heart, but they do allow you to do some magic. Plus, learning about them can help you understand what exactly happens behind the scenes when you instantiate a class.&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 #156: Virtual Environment Structure &amp; Surveying the Packaging Ecosystem</title>
      <id>https://realpython.com/podcasts/rpp/156/</id>
      <link href="https://realpython.com/podcasts/rpp/156/"/>
      <updated>2023-05-12T12:00:00+00:00</updated>
      <summary>How do Python virtual environments work under the hood? How does understanding these concepts help you with managing them for your projects? This week on the show, CPython core developer Brett Cannon returns to discuss his recent articles about virtual environments and the Python packaging landscape.</summary>
      <content type="html">
        &lt;p&gt;How do Python virtual environments work under the hood? How does understanding these concepts help you with managing them for your projects? This week on the show, CPython core developer Brett Cannon returns to discuss his recent articles about virtual environments and the Python packaging landscape.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Getting the Most Out of the Python Standard REPL</title>
      <id>https://realpython.com/courses/python-repl/</id>
      <link href="https://realpython.com/courses/python-repl/"/>
      <updated>2023-05-09T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to use the Python standard REPL (Read-Eval-Print Loop) to run your code interactively. This tool will allow you to test new ideas, explore and experiment with new tools and libraries, refactor and debug your code, try out examples, and more.</summary>
      <content type="html">
        &lt;p&gt;The Python standard shell, or &lt;strong&gt;REPL (Read-Eval-Print Loop)&lt;/strong&gt;, allows you to run Python code interactively while working on a project or learning the language. This tool is available in every Python installation, so you can use it at any moment.&lt;/p&gt;
&lt;p&gt;As a Python developer, you&amp;rsquo;ll spend a considerable part of your coding time in a REPL session because this tool allows you to test new ideas, explore and experiment with new tools and libraries, refactor and debug your code, and try out examples.&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;Run the Python &lt;strong&gt;standard REPL&lt;/strong&gt;, or interactive shell&lt;/li&gt;
&lt;li&gt;Write and execute &lt;strong&gt;Python code&lt;/strong&gt; in an interactive session&lt;/li&gt;
&lt;li&gt;Quickly &lt;strong&gt;edit&lt;/strong&gt;, &lt;strong&gt;modify&lt;/strong&gt;, and &lt;strong&gt;reuse&lt;/strong&gt; code in a REPL session&lt;/li&gt;
&lt;li&gt;Get &lt;strong&gt;help&lt;/strong&gt; and &lt;strong&gt;introspect&lt;/strong&gt; your code in an interactive session&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tweak&lt;/strong&gt; some features of the standard REPL&lt;/li&gt;
&lt;li&gt;Identify the standard REPL&amp;rsquo;s &lt;strong&gt;missing features&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You&amp;rsquo;ll also learn about available feature-rich REPLs, such as &lt;a href=&quot;https://realpython.com/python-idle/&quot;&gt;IDLE&lt;/a&gt;, &lt;a href=&quot;https://ipython.readthedocs.io/en/stable/#ipython-documentation&quot;&gt;IPython&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/bpython-alternative-python-repl/&quot;&gt;bpython&lt;/a&gt;, and &lt;a href=&quot;https://github.com/jonathanslenders/ptpython/&quot;&gt;ptpython&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To get the most out of this video course, you should be familiar with your operating system&amp;rsquo;s command line, or terminal. You should also know the basics of using the &lt;a href=&quot;https://realpython.com/courses/command-line-interfaces/&quot;&gt;&lt;code&gt;python&lt;/code&gt; command&lt;/a&gt; to run your code.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #155: Checking Project Dependencies &amp; Python Dev Resource Collections</title>
      <id>https://realpython.com/podcasts/rpp/155/</id>
      <link href="https://realpython.com/podcasts/rpp/155/"/>
      <updated>2023-05-05T12:00:00+00:00</updated>
      <summary>How can you ensure that you&#x27;ve appropriately declared your project&#x27;s required dependencies? How do you determine what dependencies are missing from a third-party project that you can&#x27;t run? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;How can you ensure that you&#x27;ve appropriately declared your project&#x27;s required dependencies? How do you determine what dependencies are missing from a third-party project that you can&#x27;t run? This week on the show, Christopher Trudeau is here, 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>Publishing Python Packages to PyPI</title>
      <id>https://realpython.com/courses/pypi-publish-python-package/</id>
      <link href="https://realpython.com/courses/pypi-publish-python-package/"/>
      <updated>2023-05-02T14:00:00+00:00</updated>
      <summary>In this video course, you’ll learn how to create a Python package for your project and how to publish it to PyPI, the Python Package Index. Quickly get up to speed on everything from naming your package to configuring it using setup.cfg.</summary>
      <content type="html">
        &lt;p&gt;&lt;a href=&quot;https://pypi.org/&quot;&gt;PyPI&lt;/a&gt; is the public hosting service where open-source Python packages live.
When you &lt;code&gt;pip install&lt;/code&gt; a package, that&amp;rsquo;s where it fetches it from. In this course,
you&amp;rsquo;ll learn all about the structures of a package and how to upload your own
to the PyPI server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn about:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Why &lt;strong&gt;packages&lt;/strong&gt; and &lt;strong&gt;virtual environments&lt;/strong&gt; exist&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;structure&lt;/strong&gt; a package&lt;/li&gt;
&lt;li&gt;How to use &lt;strong&gt;build systems&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The contents of the &lt;strong&gt;&lt;code&gt;pyproject.toml&lt;/code&gt; file&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to use the &lt;strong&gt;&lt;code&gt;build&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;twine&lt;/code&gt;&lt;/strong&gt; tools&lt;/li&gt;
&lt;li&gt;What the &lt;strong&gt;Flit&lt;/strong&gt; and &lt;strong&gt;Poetry&lt;/strong&gt; tools offer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Throughout this course, you&amp;rsquo;ll work with an example project: a &lt;code&gt;reader&lt;/code&gt; package that can be used to read Real Python tutorials in your console.&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 #154: Targeting WebAssembly Platforms &amp; Distilling a Minimum Viable Python</title>
      <id>https://realpython.com/podcasts/rpp/154/</id>
      <link href="https://realpython.com/podcasts/rpp/154/"/>
      <updated>2023-04-28T12:00:00+00:00</updated>
      <summary>Are you familiar with the different versions of WebAssembly? Could WASM be the &quot;write once, run everywhere&quot; solution that developers have searched for? Where does distributing Python applications fit in the narrative? This week on the show, we have CPython core developer Brett Cannon to discuss his recent articles about WebAssembly and MVPy.</summary>
      <content type="html">
        &lt;p&gt;Are you familiar with the different versions of WebAssembly? Could WASM be the &quot;write once, run everywhere&quot; solution that developers have searched for? Where does distributing Python applications fit in the narrative? This week on the show, we have CPython core developer Brett Cannon to discuss his recent articles about WebAssembly and MVPy.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Using Python&#x27;s assert to Debug and Test Your Code</title>
      <id>https://realpython.com/courses/python-assert-statement/</id>
      <link href="https://realpython.com/courses/python-assert-statement/"/>
      <updated>2023-04-25T14:00:00+00:00</updated>
      <summary>In this course, you&#x27;ll learn how to use Python&#x27;s assert statement to document, debug, and test code in development. You&#x27;ll learn how assertions might be disabled in production code, so you shouldn&#x27;t use them to validate data. You&#x27;ll also learn about a few common pitfalls of assertions in Python.</summary>
      <content type="html">
        &lt;p&gt;Python&amp;rsquo;s &lt;code&gt;assert&lt;/code&gt; statement allows you to write &lt;a href=&quot;https://en.wikipedia.org/wiki/Sanity_check&quot;&gt;sanity checks&lt;/a&gt; in your code. These checks are known as &lt;strong&gt;assertions&lt;/strong&gt;, and you can use them to test if certain assumptions remain true while you&amp;rsquo;re developing your code. If any of your assertions turn false, then you have a bug in your code.&lt;/p&gt;
&lt;p&gt;Assertions are a convenient tool for &lt;strong&gt;documenting&lt;/strong&gt;, &lt;strong&gt;debugging&lt;/strong&gt;, and &lt;strong&gt;testing&lt;/strong&gt; code during development. Once you&amp;rsquo;ve debugged and tested your code with the help of assertions, then you can turn them off to optimize the code for production. Assertions will help you make your code more efficient, robust, and reliable.&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;assertions&lt;/strong&gt; are and when to use them&lt;/li&gt;
&lt;li&gt;How Python&amp;rsquo;s &lt;strong&gt;&lt;code&gt;assert&lt;/code&gt; statement&lt;/strong&gt; works&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;assert&lt;/code&gt; can help you &lt;strong&gt;document&lt;/strong&gt;, &lt;strong&gt;debug&lt;/strong&gt;, and &lt;strong&gt;test&lt;/strong&gt; your code&lt;/li&gt;
&lt;li&gt;How assertions can be &lt;strong&gt;disabled&lt;/strong&gt; to improve performance in production&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;common pitfalls&lt;/strong&gt; you might face when using &lt;code&gt;assert&lt;/code&gt; statements&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this video course, you should have previous knowledge of &lt;a href=&quot;https://realpython.com/python-operators-expressions/&quot;&gt;expressions and operators&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;conditional statements&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-exceptions/&quot;&gt;exceptions&lt;/a&gt;. Having a basic understanding of &lt;a href=&quot;https://realpython.com/documenting-python-code/&quot;&gt;documenting&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-debugging-pdb/&quot;&gt;debugging&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-testing/&quot;&gt;testing&lt;/a&gt; Python code is also a plus.&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 #153: Seeking Faster Text Processing &amp; Python&#x27;s .__repr__() vs .__str__()</title>
      <id>https://realpython.com/podcasts/rpp/153/</id>
      <link href="https://realpython.com/podcasts/rpp/153/"/>
      <updated>2023-04-14T12:00:00+00:00</updated>
      <summary>What can you do if your text manipulation in Python is slowing you down? Are there faster alternatives using a compiled extension? This week on the show, Christopher Trudeau is here, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What can you do if your text manipulation in Python is slowing you down? Are there faster alternatives using a compiled extension? This week on the show, Christopher Trudeau is here, 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 #152: Automate Processes and Distribute Python Tools With RPA and RCC</title>
      <id>https://realpython.com/podcasts/rpp/152/</id>
      <link href="https://realpython.com/podcasts/rpp/152/"/>
      <updated>2023-04-07T12:00:00+00:00</updated>
      <summary>Are you exploring automation of your repetitive business tasks with Python? How are you going to share your helpful tools with co-workers? This week on the show, Sampo Ahokas from Robocorp is here to discuss robotic process automation (RPA) and distribution of these robots.</summary>
      <content type="html">
        &lt;p&gt;Are you exploring automation of your repetitive business tasks with Python? How are you going to share your helpful tools with co-workers? This week on the show, Sampo Ahokas from Robocorp is here to discuss robotic process automation (RPA) and distribution of these robots.&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>
