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

  
    <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://docs.python.org/3/glossary.html#term-special-method&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>How to Launch an HTTP Server in One Line of Python Code</title>
      <id>https://realpython.com/python-http-server/</id>
      <link href="https://realpython.com/python-http-server/"/>
      <updated>2023-05-22T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to host files with a single command using an HTTP server built into Python. You&#x27;ll also extend it by making a miniature web framework able to serve dynamic content from HTML templates. Along the way, you&#x27;ll run CGI scripts and use encryption over HTTPS.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Traditionally, if you wanted to handle &lt;a href=&quot;https://realpython.com/urllib-request/&quot;&gt;HTTP requests&lt;/a&gt; and serve &lt;strong&gt;static content&lt;/strong&gt; from files, then you had to set up a full-fledged web server like &lt;a href=&quot;https://httpd.apache.org/&quot;&gt;Apache&lt;/a&gt; or &lt;a href=&quot;https://www.nginx.com/&quot;&gt;NGINX&lt;/a&gt;, which could be a tedious process. Building a &lt;strong&gt;dynamic web application&lt;/strong&gt; requires installing a web framework, such as &lt;a href=&quot;https://realpython.com/learning-paths/django-web-development/&quot;&gt;Django&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/flask-connexion-rest-api/&quot;&gt;Flask&lt;/a&gt;, or &lt;a href=&quot;https://realpython.com/fastapi-python-web-apis/&quot;&gt;FastAPI&lt;/a&gt;, which adds yet another complexity layer. Fortunately, you can take advantage of a basic HTTP server built into Python to avoid all this hassle.&lt;/p&gt;
&lt;p&gt;Python’s HTTP server can come in handy when you want to quickly &lt;strong&gt;share a bunch of files&lt;/strong&gt; with students in a classroom or anyone else who’s connected to the same network as you. Maybe you need to host static resources downloaded from the Internet for &lt;strong&gt;offline development&lt;/strong&gt; of a &lt;a href=&quot;https://realpython.com/pyscript-python-in-browser/#download-pyscript-for-offline-development&quot;&gt;PyScript&lt;/a&gt; application or spin up a local web server to experiment with the HTTP protocol in your terminal. You may also have a &lt;a href=&quot;https://realpython.com/run-python-scripts/&quot;&gt;Python script&lt;/a&gt; that should be triggered remotely.&lt;/p&gt;
&lt;p&gt;You can do all of this with a single command thanks to the &lt;a href=&quot;https://docs.python.org/3/library/http.server.html&quot;&gt;&lt;code&gt;http.server&lt;/code&gt;&lt;/a&gt; module that ships with the Python standard library!&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-http-server-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-http-server-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 write a one-liner Python HTTP server and more.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;how-to-start-pythons-httpserver-in-the-command-line&quot;&gt;How to Start Python’s &lt;code&gt;http.server&lt;/code&gt; in the Command Line&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-start-pythons-httpserver-in-the-command-line&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Open a command prompt or &lt;a href=&quot;https://realpython.com/terminal-commands/&quot;&gt;terminal&lt;/a&gt; window and navigate to the directory where you want to launch the HTTP server. Alternatively, on most modern operating systems, you can right-click a given folder and choose to open the terminal there. Once you’re in the correct place, type and run the following command:&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;python3 -m http.server
&lt;span class=&quot;go&quot;&gt;Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Python starts an HTTP server on port &lt;code&gt;8000&lt;/code&gt; and binds it to all the available network interfaces on your machine, which are denoted with a special &lt;a href=&quot;https://en.wikipedia.org/wiki/IP_address&quot;&gt;IP address&lt;/a&gt;. Depending on your operating system’s preference, the underlying &lt;a href=&quot;https://realpython.com/python-sockets/&quot;&gt;&lt;code&gt;socket&lt;/code&gt;&lt;/a&gt; library may choose to bind to IPv4 address &lt;code&gt;0.0.0.0&lt;/code&gt; or IPv6 address &lt;code&gt;::&lt;/code&gt;. Either way, anyone on your network can use your computer’s IP address to access the HTTP server that you just started.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To find your local IP address, you can check your network settings or, depending on your operating system, use one of the commands below:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;macOS:&lt;/strong&gt; &lt;code&gt;ifconfig&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Windows:&lt;/strong&gt; &lt;code&gt;ipconfig&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Linux:&lt;/strong&gt; &lt;code&gt;ip address&lt;/code&gt; or &lt;code&gt;hostname -I&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Visiting a website like &lt;a href=&quot;https://ifconfig.me/&quot;&gt;ifconfig.me&lt;/a&gt; will reveal your public IP address, which is typically the address of your router. It’s most likely different from the local address of the device that you’re using. Unless you’ve configured &lt;a href=&quot;https://en.wikipedia.org/wiki/Port_forwarding&quot;&gt;port forwarding&lt;/a&gt; in your router, the HTTP server won’t be accessible from the Internet through your public address.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;If the default port number, &lt;code&gt;8000&lt;/code&gt;, is unavailable, then you’ll see the following error when you make an attempt to start the server:&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;python3 -m http.server
&lt;span class=&quot;go&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  ...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;OSError: [Errno 98] Address already in use&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This means that another program is currently occupying that port. To fix this problem, you can find the offending program and forcefully stop it. However, because that may not always be desirable, you can also assign a different port to your server. To explicitly set the port number that your HTTP server should be listening on, append it as a parameter:&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;python3 -m http.server &lt;span class=&quot;m&quot;&gt;8080&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Sometimes, it takes trial and error to find a free port, especially when many services are running in the background while listening for network traffic on different ports. Remember that a given port can belong to at most one program at a time, but the same program can own multiple ports simultaneously. Usually, each port is associated with a different service.&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; Web browsers automatically use port &lt;code&gt;80&lt;/code&gt; to communicate with web servers over the HTTP protocol, even when you don’t explicitly specify the port number in the address bar. For example, these two addresses are equivalent:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http://localhost:80&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http://localhost&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Port &lt;code&gt;80&lt;/code&gt; is a standard port reserved for HTTP traffic. However, if you’d like to start a local web server on that special port, then you’ll have to run the corresponding command as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Superuser&quot;&gt;superuser&lt;/a&gt; with administrative privileges. Otherwise, you’ll get another error:&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;python3 -m http.server &lt;span class=&quot;m&quot;&gt;80&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;  ...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;PermissionError: [Errno 13] Permission denied&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;All port numbers below &lt;code&gt;1024&lt;/code&gt; require administrative privileges. You can prefix a command with &lt;a href=&quot;https://en.wikipedia.org/wiki/Sudo&quot;&gt;&lt;code&gt;sudo&lt;/code&gt;&lt;/a&gt; to run it as the root user on macOS and Linux. On the other hand, to run a similar command with elevated privileges on Windows, you must first open the terminal as an administrator.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;For security reasons, you may restrict access to your HTTP server by running it on an address belonging to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Loopback&quot;&gt;virtual loopback interface&lt;/a&gt; or &lt;code&gt;localhost&lt;/code&gt;, which no one except you will be able to speak to. You can bind a specific network interface or IP address by using the &lt;code&gt;-b&lt;/code&gt; option:&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;python3 -m http.server -b &lt;span class=&quot;m&quot;&gt;127&lt;/span&gt;.0.0.42 &lt;span class=&quot;m&quot;&gt;8080&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Serving HTTP on 127.0.0.42 port 8080 (http://127.0.0.42:8080/) ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this case, you combine the &lt;code&gt;-b&lt;/code&gt; option, which binds a specific address on the loopback interface, with a positional argument determining the port number. These parameters ensure that your server will only be accessible from the local machine.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; When you rely on the defaults, Python will bind to a network address family that your operating system prefers. To enforce a different address, you can use the &lt;code&gt;-b&lt;/code&gt; option:&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 http.server -b &lt;span class=&quot;s2&quot;&gt;&quot;::&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Serving HTTP on :: port 8000 (http://[::]:8000/) ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The double colon (&lt;code&gt;::&lt;/code&gt;) is a shorthand notation for &lt;a href=&quot;https://en.wikipedia.org/wiki/IPv6_address#Unspecified_address&quot;&gt;IPv6 unspecified address&lt;/a&gt;. In most cases, binding to an IPv6 address will enable &lt;a href=&quot;https://en.wikipedia.org/wiki/IPv6#Dual-stack_IP_implementation&quot;&gt;dual-stack IP&lt;/a&gt; mode, letting you connect to the server through both IPv4 and IPv6 addresses. However, it doesn’t work the other way around, so binding to an IPv4 address won’t allow you to connect to the server through an IPv6 address.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;By default, Python serves the files located in your &lt;a href=&quot;https://en.wikipedia.org/wiki/Working_directory&quot;&gt;current working directory&lt;/a&gt; where you executed the command to start the server. So, when you visit the home address (&lt;code&gt;/&lt;/code&gt;) of your server in a web browser, then you’ll see all the files and folders in the corresponding directory:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/web_browser.b85bdf6e08ad.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block border &quot; src=&quot;https://files.realpython.com/media/web_browser.b85bdf6e08ad.png&quot; width=&quot;1384&quot; height=&quot;961&quot; srcset=&quot;https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/web_browser.b85bdf6e08ad.png&amp;amp;w=346&amp;amp;sig=bd888c456aaea9cdc26d6309d2982621655b6d70 346w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/web_browser.b85bdf6e08ad.png&amp;amp;w=461&amp;amp;sig=20a82e8bc55d9d0bf75d2abae3fc6e7db65151d7 461w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/web_browser.b85bdf6e08ad.png&amp;amp;w=692&amp;amp;sig=4c2b9b02ede670950959e2739477637aa20d929e 692w, https://files.realpython.com/media/web_browser.b85bdf6e08ad.png 1384w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Directory Listing Generated by Python&#x27;s HTTP Server&quot; data-asset=&quot;5090&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Directory listing generated by Python&#x27;s HTTP server&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;Here, you see the content of your &lt;a href=&quot;https://en.wikipedia.org/wiki/Home_directory&quot;&gt;home directory&lt;/a&gt;, which is where the server must’ve been started in the command line. Clicking one of the displayed links will send another request to the server, letting you navigate the directory tree in the browser.&lt;/p&gt;
&lt;p&gt;You may instruct the server to associate its home address (&lt;code&gt;/&lt;/code&gt;) with a completely different directory by specifying the optional &lt;code&gt;-d&lt;/code&gt; parameter:&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;python3 -m http.server -d ~/Pictures/
&lt;span class=&quot;go&quot;&gt;Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, the server will list the pictures in one of your home directory’s subfolders. Your shell expands the tilde character (&lt;code&gt;~&lt;/code&gt;) into the home directory of the current user. Note that you can use both &lt;strong&gt;relative&lt;/strong&gt; and &lt;strong&gt;absolute paths&lt;/strong&gt; to indicate a directory to serve over HTTP.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-http-server/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-http-server/ »&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>ChatGPT: Your Personal Python Coding Mentor</title>
      <id>https://realpython.com/chatgpt-coding-mentor-python/</id>
      <link href="https://realpython.com/chatgpt-coding-mentor-python/"/>
      <updated>2023-05-17T14:00:00+00:00</updated>
      <summary>Large language models have gained popularity since OpenAI released ChatGPT. In this tutorial, you&#x27;ll learn how to use ChatGPT as your Python coding mentor. You&#x27;ll study a variety of use cases, learn how to interpret results, and see that you need to beware of incorrect and irrelevant responses.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Large_language_model&quot;&gt;Large language models (LLMs)&lt;/a&gt; have quickly gained popularity since OpenAI released ChatGPT for public access. Since then, people have used ChatGPT for fun, creative, and useful purposes. If you’ve dreamed about using ChatGPT as your &lt;strong&gt;Python coding mentor&lt;/strong&gt;, then keep on reading.&lt;/p&gt;
&lt;p&gt;Using ChatGPT as your mentor doesn’t mean that you should try to build a software solution without knowing anything about programming. Instead, you’ll focus on using ChatGPT as a &lt;strong&gt;learning tool&lt;/strong&gt;. It probably can’t replace you as a programmer, but it &lt;em&gt;can&lt;/em&gt; help you to improve your code and learn in the process.&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;Set up ChatGPT&lt;/strong&gt; for use&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Debug&lt;/strong&gt; your code using ChatGPT&lt;/li&gt;
&lt;li&gt;Improve your &lt;strong&gt;code style&lt;/strong&gt; and &lt;strong&gt;code quality&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pair program&lt;/strong&gt; with ChatGPT&lt;/li&gt;
&lt;li&gt;Explore &lt;strong&gt;alternative implementations&lt;/strong&gt; of a code snippet&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Get answers&lt;/strong&gt; to your programming questions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll also get to see examples of how ChatGPT can produce incorrect and irrelevant solutions, and you’ll learn how you can improve its responses by working on better &lt;strong&gt;prompts&lt;/strong&gt;. In the downloadable materials, you get access to all the code snippets in the tutorial, as well as all the prompts that you’ll use to interact with ChatGPT:&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/chatgpt-coding-mentor-python-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-chatgpt-coding-mentor-python-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code and engineered prompts&lt;/a&gt; that show you how to boost your Python programming skills with the help of ChatGPT.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;set-up-your-chatgpt-coding-mentor&quot;&gt;Set Up Your ChatGPT Coding Mentor&lt;a class=&quot;headerlink&quot; href=&quot;#set-up-your-chatgpt-coding-mentor&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To access ChatGPT, you only need to create an account with OpenAI. When you first head to &lt;a href=&quot;https://chat.openai.com/&quot;&gt;chat.openai.com&lt;/a&gt;, then you’ll be prompted to either sign in or sign up:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/chatgpt-landing.d3911ef24683.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block border &quot; src=&quot;https://files.realpython.com/media/chatgpt-landing.d3911ef24683.png&quot; width=&quot;2880&quot; height=&quot;1800&quot; srcset=&quot;https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-landing.d3911ef24683.png&amp;amp;w=720&amp;amp;sig=2f386133ba49267835c48e0a025d744b98a32e09 720w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-landing.d3911ef24683.png&amp;amp;w=960&amp;amp;sig=e153fab6d128674ed85044c75ecda99793fbce29 960w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-landing.d3911ef24683.png&amp;amp;w=1440&amp;amp;sig=9f67846e6bd2f5dd41b61b08b86e62ea6aa4f938 1440w, https://files.realpython.com/media/chatgpt-landing.d3911ef24683.png 2880w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Landing page of ChatGPT giving you options to sign up or sign in&quot; data-asset=&quot;5009&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;If you’ve already played with ChatGPT before and have an active account, then sign in and skip to the &lt;a href=&quot;#beware-of-incorrect-and-irrelevant-information&quot;&gt;next section&lt;/a&gt;. Otherwise, continue reading for a quick walk-through on signing up for the service.&lt;/p&gt;
&lt;p&gt;If you don’t have an account with OpenAI yet, then click on &lt;em&gt;Sign up&lt;/em&gt;. You’ll be redirected to a page that allows you to sign up using your Google or Microsoft account or a personal email address:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/chatgpt-signup.28ca2d16c5b2.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block border &quot; src=&quot;https://files.realpython.com/media/chatgpt-signup.28ca2d16c5b2.png&quot; width=&quot;2880&quot; height=&quot;1800&quot; srcset=&quot;https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-signup.28ca2d16c5b2.png&amp;amp;w=720&amp;amp;sig=8d250c41cdd4195103b06ba74024ad101f23b39a 720w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-signup.28ca2d16c5b2.png&amp;amp;w=960&amp;amp;sig=ffdb6f41e33260d8067adde6da0e6fca96fff17e 960w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-signup.28ca2d16c5b2.png&amp;amp;w=1440&amp;amp;sig=3870b171e23b2e8f556c389b1062cfe1dfd9ae86 1440w, https://files.realpython.com/media/chatgpt-signup.28ca2d16c5b2.png 2880w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;ChatGPT sign up page, giving options to create an account via email, Google, or Microsoft&quot; data-asset=&quot;5010&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;If you choose to sign up using your email address, then you’ll need to enter a password next. Choose a strong password and complete the sign-up process.&lt;/p&gt;
&lt;p&gt;You’ll then be redirected to the main page of ChatGPT, where you’ll get to interact with the large language model through a conversational interface where you enter questions, and the chat provides answers:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/chatgpt-main-page.ab9b61401995.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block border &quot; src=&quot;https://files.realpython.com/media/chatgpt-main-page.ab9b61401995.png&quot; width=&quot;2880&quot; height=&quot;1800&quot; srcset=&quot;https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-main-page.ab9b61401995.png&amp;amp;w=720&amp;amp;sig=0c161d422f43364ffc1c6fe761e3ee46603eadc9 720w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-main-page.ab9b61401995.png&amp;amp;w=960&amp;amp;sig=8d34bb21716658db6a66e05c4b711757261e27cb 960w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/chatgpt-main-page.ab9b61401995.png&amp;amp;w=1440&amp;amp;sig=90275f733ec590e50ae5bf66a74287625584e3bd 1440w, https://files.realpython.com/media/chatgpt-main-page.ab9b61401995.png 2880w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;ChatGPT main chat page, showing the conversation tab on the left side, and suggested prompts to the right&quot; data-asset=&quot;5012&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;In the future, you can navigate to &lt;code&gt;chat.openai.com&lt;/code&gt; to directly access this page since you’ve completed the sign-up process. Every so often, after your browser session expires, you’ll have to log in again.&lt;/p&gt;
&lt;h2 id=&quot;beware-of-incorrect-and-irrelevant-information&quot;&gt;Beware of Incorrect and Irrelevant Information&lt;a class=&quot;headerlink&quot; href=&quot;#beware-of-incorrect-and-irrelevant-information&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Now that you’ve signed up for ChatGPT, you probably want to give it a spin! But before you hit the throttle, it’s important to know what kinds of issues you might run into. While large language models offer several new possibilities for enhancing your studies, you need to remember the potentially negative effects of using ChatGPT as your coding mentor:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Overreliance:&lt;/strong&gt; Leaning too heavily on ChatGPT for answers can hinder your own learning. You build brain paths by thinking, struggling, checking your understanding, and memorizing information.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accuracy:&lt;/strong&gt; ChatGPT’s responses may often be inaccurate or irrelevant. You need to fact-check all of its answers! Otherwise, you might learn wrong concepts and bad practices.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this section and throughout the tutorial, you’ll encounter a few examples of incorrect and irrelevant answers. Hopefully, these examples will help you keep in mind that even if ChatGPT’s responses seem logical at first sight, they’re not always correct. Sometimes the errors in a response are so subtle that you’ll spot them only if you’re an expert programmer.&lt;/p&gt;
&lt;p&gt;In a classic workflow with ChatGPT, you ask a question in the chat interface, and the underlying language model, &lt;a href=&quot;https://en.wikipedia.org/wiki/GPT-3#GPT-3.5&quot;&gt;GPT-3.5&lt;/a&gt;, will create a reply that you’ll see pop up as a chat response. ChatGPT will even format the replies in useful ways. For example, go ahead and ask the chat to generate some useful Python learning material for you:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You:&lt;/strong&gt; Please show me a table with a cheat sheet of Python’s syntax.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When you ask ChatGPT for a table, then it’ll create &lt;a href=&quot;https://www.markdownguide.org/getting-started/#what-is-markdown&quot;&gt;Markdown&lt;/a&gt; that the chat interface knows to display beautifully. As for the content of that cheat sheet, it’ll pick &lt;em&gt;some&lt;/em&gt; of Python’s syntax, and the results &lt;em&gt;might&lt;/em&gt; be correct and relevant:&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/815373647?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;The table that you’ll receive as output will most likely be different. It could be quite similar, but it doesn’t have to be. The LLM behind ChatGPT will always create a new response, predicting the most likely next piece of information based on its training. But the output isn’t deterministic, and it’s often even incorrect.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/chatgpt-coding-mentor-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/chatgpt-coding-mentor-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>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>Using and Creating Global Variables in Your Python Functions</title>
      <id>https://realpython.com/python-use-global-variable-in-function/</id>
      <link href="https://realpython.com/python-use-global-variable-in-function/"/>
      <updated>2023-05-15T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use global variables in Python functions using the global keyword or the built-in globals() function. You&#x27;ll also learn a few strategies to avoid relying on global variables because they can lead to code that&#x27;s difficult to understand, debug, and maintain.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;A &lt;strong&gt;global variable&lt;/strong&gt; is a variable that you can use from any part of a program, including within &lt;strong&gt;functions&lt;/strong&gt;. Using global variables inside your Python functions can be tricky. You’ll need to differentiate between accessing and changing the values of the target global variable if you want your code to work correctly.&lt;/p&gt;
&lt;p&gt;Global variables can play a fundamental role in many software projects because they enable data sharing across an entire program. However, you should use them judiciously to avoid issues.&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 &lt;strong&gt;global variables&lt;/strong&gt; and how they work in Python&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access&lt;/strong&gt; global variables within your Python functions directly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modify&lt;/strong&gt; and &lt;strong&gt;create&lt;/strong&gt; global variables within functions using the &lt;strong&gt;&lt;code&gt;global&lt;/code&gt; keyword&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access&lt;/strong&gt;, &lt;strong&gt;create&lt;/strong&gt;, and &lt;strong&gt;modify&lt;/strong&gt; global variables within your functions with the &lt;strong&gt;&lt;code&gt;globals()&lt;/code&gt; function&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Explore strategies to &lt;strong&gt;avoid using global variables&lt;/strong&gt; in Python code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To follow along with this tutorial, you should have a solid understanding of Python programming, including fundamental concepts such as &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-scope-legb-rule/&quot;&gt;scope&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/&quot;&gt;mutability&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-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 Download:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-use-global-variable-in-function-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-use-global-variable-in-function-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to get the sample code&lt;/a&gt; that will help you understand when and how to work with global variables in your Python functions.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;using-global-variables-in-python-functions&quot;&gt;Using Global Variables in Python Functions&lt;a class=&quot;headerlink&quot; href=&quot;#using-global-variables-in-python-functions&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Global &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt; are those that you can access and modify from anywhere in your code. In Python, you’ll typically define global variables at the &lt;a href=&quot;https://realpython.com/python-modules-packages/&quot;&gt;module&lt;/a&gt; level. So, the containing module is their &lt;strong&gt;scope&lt;/strong&gt;. &lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can also define global variables inside &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;, as you’ll learn in the section &lt;a href=&quot;#creating-global-variables-inside-a-function&quot;&gt;Creating Global Variables Inside a Function&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Once you’ve defined a global variable, you can use it from within the module itself or from within other modules in your code. You can also use global variables in your functions. However, those cases can get a bit confusing because of differences between &lt;strong&gt;accessing&lt;/strong&gt; and &lt;strong&gt;modifying&lt;/strong&gt; global variables in functions.&lt;/p&gt;
&lt;p&gt;To understand these differences, consider that Python can look for variables in four different scopes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://realpython.com/python-scope-legb-rule/#functions-the-local-scope&quot;&gt;local&lt;/a&gt;, or function-level, scope, which exists inside functions&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://realpython.com/python-scope-legb-rule/#nested-functions-the-enclosing-scope&quot;&gt;enclosing&lt;/a&gt;, or non-local, scope, which appears in nested functions&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://realpython.com/python-scope-legb-rule/#modules-the-global-scope&quot;&gt;global&lt;/a&gt; scope, which exists at the module level&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://realpython.com/python-scope-legb-rule/#builtins-the-built-in-scope&quot;&gt;built-in&lt;/a&gt; scope, which is a special scope for Python’s built-in names&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To illustrate, say that you’re inside an &lt;a href=&quot;https://realpython.com/inner-functions-what-are-they-good-for/&quot;&gt;inner&lt;/a&gt; function. In that case, Python can look for names in all four scopes.&lt;/p&gt;
&lt;p&gt;When you access a variable in that inner function, Python first looks inside that function. If the variable doesn’t exist there, then Python continues with the enclosing scope of the outer function. If the variable isn’t defined there either, then Python moves to the global and built-in scopes in that order. If Python finds the variable, then you get the value back. Otherwise, you get a &lt;code&gt;NameError&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;c1&quot;&gt;# Global scope&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;outer_func&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;c1&quot;&gt;# Non-local scope&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;inner_func&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;c1&quot;&gt;# Local scope&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;some_variable&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;inner_func&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;n&quot;&gt;outer_func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
    &lt;span class=&quot;o&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;some_variable&#x27; is not defined&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;some_variable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Hello from global scope!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outer_func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Hello from global scope!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When you launch an &lt;a href=&quot;https://realpython.com/interacting-with-python/&quot;&gt;interactive session&lt;/a&gt;, it starts off at the module level of global scope. In this example, you have &lt;code&gt;outer_func()&lt;/code&gt;, which defines &lt;code&gt;inner_func()&lt;/code&gt; as a nested function. From the perspective of this nested function, its own code block represents the local scope, while the &lt;code&gt;outer_func()&lt;/code&gt; code block before the call to &lt;code&gt;inner_func()&lt;/code&gt; represents the non-local scope.&lt;/p&gt;
&lt;p&gt;If you call &lt;code&gt;outer_func()&lt;/code&gt; without defining &lt;code&gt;some_variable&lt;/code&gt; in either of your current scopes, then you get a &lt;code&gt;NameError&lt;/code&gt; exception because the name isn’t defined.&lt;/p&gt;
&lt;p&gt;If you define &lt;code&gt;some_variable&lt;/code&gt; in the global scope and then call &lt;code&gt;outer_func()&lt;/code&gt;, then you get &lt;code&gt;Hello!&lt;/code&gt; on your screen. Internally, Python has searched the local, non-local, and global scopes to find &lt;code&gt;some_variable&lt;/code&gt; and print its content. Note that you can define this variable in any of the three scopes, and Python will find it.&lt;/p&gt;
&lt;p&gt;This search mechanism makes it possible to use global variables from inside functions. However, while taking advantage of this feature, you can face a few issues. For example, accessing a variable works, but directly modifying a variable doesn’t work:&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;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;

&lt;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;access_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&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;n&quot;&gt;access_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;42&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;modify_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&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;n&quot;&gt;modify_number&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;number&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;access_number()&lt;/code&gt; function works fine. It looks for &lt;code&gt;number&lt;/code&gt; and finds it in the global scope. In contrast, &lt;code&gt;modify_number()&lt;/code&gt; doesn’t work as expected. Why doesn’t this function update the value of your global variable, &lt;code&gt;number&lt;/code&gt;? The problem is the scope of the variable. You can’t directly modify a variable from a high-level scope like global in a lower-level scope like local.&lt;/p&gt;
&lt;p&gt;Internally, Python assumes that any name directly assigned within a function is local to that function. Therefore, the local name, &lt;code&gt;number&lt;/code&gt;, shadows its global sibling.&lt;/p&gt;
&lt;p&gt;In this sense, global variables behave as read-only names. You can access their values, but you can’t modify them.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The discussion about modifying global variables inside functions revolves around &lt;a href=&quot;https://realpython.com/python-assignment-operator/#assignment-statements-and-the-assignment-operator&quot;&gt;assignment&lt;/a&gt; operations rather than &lt;a href=&quot;https://en.wikipedia.org/wiki/In-place_algorithm&quot;&gt;in-place&lt;/a&gt; mutations of &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/&quot;&gt;mutable&lt;/a&gt; objects. You’ll learn about the effects of mutability on global variables in the section &lt;a href=&quot;#understanding-how-mutability-affects-global-variables&quot;&gt;Understanding How Mutability Affects Global Variables&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Getting an &lt;a href=&quot;https://docs.python.org/3/library/exceptions.html?highlight=unboundlocalerror#UnboundLocalError&quot;&gt;&lt;code&gt;UnboundLocalError&lt;/code&gt;&lt;/a&gt; exception is another common issue when you try to modify a global variable inside a function. Consider the following demonstrative function that attempts to use some global variables:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-use-global-variable-in-function/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-use-global-variable-in-function/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>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>Python News: What&#x27;s New From April 2023</title>
      <id>https://realpython.com/python-news-april-2023/</id>
      <link href="https://realpython.com/python-news-april-2023/"/>
      <updated>2023-05-10T14:00:00+00:00</updated>
      <summary>April 2023 was a busy month for Python, with the last preview version of Python 3.12 before the planned feature freeze, a new pandas 2.0.0 release, and pip and PyPI improvements. In addition, it was the month of celebrating twenty years of PyCon US.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Spring is in bloom, bringing new and exciting developments in the Python world. The last preview release of &lt;strong&gt;Python 3.12&lt;/strong&gt; before the feature freeze, a new major version of &lt;strong&gt;pandas&lt;/strong&gt;,  &lt;code&gt;pip&lt;/code&gt; and PyPI improvements, and &lt;strong&gt;PyCon US 2023&lt;/strong&gt; are a few of them.&lt;/p&gt;
&lt;p&gt;Grab a cup of your favorite beverage, sit back comfortably in your chair, and enjoy a fresh dose of Python news from the past 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-3120-alpha-7-is-now-available&quot;&gt;Python 3.12.0 Alpha 7 Is Now Available&lt;a class=&quot;headerlink&quot; href=&quot;#python-3120-alpha-7-is-now-available&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.python.org/downloads/release/python-3120a7/&quot;&gt;Python 3.12.0 alpha 7&lt;/a&gt; became available to the public on April 4, marking the final &lt;a href=&quot;https://en.wikipedia.org/wiki/Software_release_life_cycle#Alpha&quot;&gt;alpha version&lt;/a&gt; before the planned transition to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Software_release_life_cycle#Beta&quot;&gt;beta phase&lt;/a&gt;, which will begin a partial &lt;a href=&quot;https://en.wikipedia.org/wiki/Freeze_(software_engineering)&quot;&gt;feature freeze&lt;/a&gt;. Beyond this point, most development efforts will focus on fixing bugs and making small improvements without introducing significant changes in the codebase. But existing features could be changed or dropped until the &lt;a href=&quot;https://en.wikipedia.org/wiki/Software_release_life_cycle#Release_candidate&quot;&gt;release candidate&lt;/a&gt; phase.&lt;/p&gt;
&lt;p&gt;While we’re still a few months away from the final release in October, we already have a pretty good idea about the most notable features that should make it into Python 3.12:&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;&lt;a href=&quot;https://docs.python.org/3.12/howto/perf_profiling.html#perf-profiling&quot;&gt;Support for the Linux &lt;code&gt;perf&lt;/code&gt; profiler&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0684/&quot;&gt;A step toward multithreaded parallelism&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0698/&quot;&gt;An &lt;code&gt;@override&lt;/code&gt; decorator for static typing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0692/&quot;&gt;More precise &lt;code&gt;**kwargs&lt;/code&gt; typing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0695/&quot;&gt;New syntax for specifying generic types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0679/&quot;&gt;Parentheses in &lt;code&gt;assert&lt;/code&gt; statements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/faster-cpython/ideas/wiki/Python-3.12-Goals#multi-threaded-parallelism&quot;&gt;Various performance and memory optimizations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Numerous &lt;a href=&quot;https://docs.python.org/3.12/whatsnew/3.12.html#deprecated&quot;&gt;deprecations&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/3.12/whatsnew/3.12.html#removed&quot;&gt;removals&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But you don’t have to wait until the fall to get your hands on these upcoming features. You can check them out today by installing a &lt;a href=&quot;https://realpython.com/python-pre-release/&quot;&gt;pre-release version of Python&lt;/a&gt;, remembering that alpha and beta releases are solely meant for testing and experimenting. So, never use them in production!&lt;/p&gt;
&lt;p&gt;If you happen to find something that isn’t working as expected, then don’t hesitate to submit a bug report through Python’s &lt;a href=&quot;https://github.com/python/cpython/issues&quot;&gt;issue tracker&lt;/a&gt; on GitHub. Testing pre-release versions of Python is one of the reasons why they’re available to early adopters in the first place. The whole Python community will surely appreciate your help in making the language as stable and reliable as possible.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For a full list of features implemented in the Python 3.12.0 alpha 7 release, have a glimpse at its &lt;a href=&quot;https://docs.python.org/3.12/whatsnew/changelog.html#python-3-12-0-alpha-7&quot;&gt;changelog&lt;/a&gt;, which includes links to the respective GitHub tickets.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The Python 3.12.0 alpha 7 release brings us one step closer to the final version, but there’s still a lot of work to be done. These ongoing efforts may sometimes affect the official &lt;a href=&quot;https://peps.python.org/pep-0693/#schedule&quot;&gt;release schedule&lt;/a&gt;, so keep an eye on it and stay tuned for more updates in the coming months.&lt;/p&gt;
&lt;h2 id=&quot;pandas-20-receives-a-major-update-with-pyarrow-integration&quot;&gt;pandas 2.0 Receives a Major Update With PyArrow Integration&lt;a class=&quot;headerlink&quot; href=&quot;#pandas-20-receives-a-major-update-with-pyarrow-integration&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The popular Python data analysis and manipulation library &lt;a href=&quot;https://realpython.com/learning-paths/pandas-data-science/&quot;&gt;pandas&lt;/a&gt; has recently released its latest version, pandas 2.0.0, followed by a patch release shortly after. These updates finalize a &lt;a href=&quot;https://realpython.com/python-news-february-2023/#release-candidate-for-pandas-200-announced&quot;&gt;release candidate&lt;/a&gt; that became available a few months ago.&lt;/p&gt;
&lt;p&gt;Historically, pandas has relied on &lt;a href=&quot;https://realpython.com/numpy-tutorial/&quot;&gt;NumPy&lt;/a&gt; as its back end for storing &lt;a href=&quot;https://realpython.com/pandas-dataframe/&quot;&gt;&lt;code&gt;DataFrame&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/pandas-python-explore-dataset/#understanding-series-objects&quot;&gt;&lt;code&gt;Series&lt;/code&gt;&lt;/a&gt; containers in memory. This release introduces an exciting new development in the form of optional &lt;a href=&quot;https://arrow.apache.org/docs/python/&quot;&gt;PyArrow&lt;/a&gt; engine support, providing the &lt;a href=&quot;https://arrow.apache.org/&quot;&gt;Apache Arrow&lt;/a&gt; columnar data representation. However, nothing is changing by default, as the developers behind pandas aim to accommodate their large user base and avoid introducing breaking changes.&lt;/p&gt;
&lt;p&gt;You now have the option to request the PyArrow back end instead of NumPy, as you can see in the following code snippets:&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;pandas&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pd&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;pd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Series&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;None&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;n&quot;&gt;dtype&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;int64[pyarrow]&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0       1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1       2&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2    &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;3       4&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;dtype: int64[pyarrow]&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;df&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_csv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;file.csv&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;engine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;pyarrow&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dtype_backend&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;pyarrow&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;class &#x27;pandas.core.frame.DataFrame&#x27;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;RangeIndex: 21 entries, 0 to 20&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Data columns (total 9 columns):&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; #   Column          Non-Null Count  Dtype&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;---  ------          --------------  -----&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 0   date            21 non-null     date32[day][pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 1   transaction_no  21 non-null     int64[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 2   payment_method  21 non-null     string[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 3   category        21 non-null     string[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 4   item            21 non-null     string[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 5   qty             21 non-null     double[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 6   price           21 non-null     string[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 7   subtotal        21 non-null     string[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; 8   comment         21 non-null     string[pyarrow]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;dtypes: date32[day][pyarrow](1), double[pyarrow](1), int64[pyarrow](1), string[pyarrow](6)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;memory usage: 1.8 KB&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/python-news-april-2023/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-april-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>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>Build Robust Continuous Integration With Docker and Friends</title>
      <id>https://realpython.com/docker-continuous-integration/</id>
      <link href="https://realpython.com/docker-continuous-integration/"/>
      <updated>2023-05-08T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll use Docker and GitHub Actions to build a robust continuous integration pipeline for a multi-container web application consisting of Flask and Redis. Along the way, you&#x27;ll learn how to dockerize a Python web application.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Continuous integration (CI) has become essential to software development, allowing teams to merge code changes frequently and catch errors early. Docker containers help facilitate the continuous integration process by providing a consistent environment where you can test and ship code on each commit.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll learn how to use Docker to create a robust continuous integration pipeline for a Flask web application. You’ll go through the steps of developing and testing the application locally, containerizing it, orchestrating containers using Docker Compose, and defining a CI pipeline using GitHub Actions. By the end of this tutorial, you’ll be able to create a fully automated CI pipeline for your web applications.&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;Run a &lt;strong&gt;Redis server&lt;/strong&gt; locally in a &lt;strong&gt;Docker container&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dockerize&lt;/strong&gt; a Python &lt;strong&gt;web application&lt;/strong&gt; written in &lt;strong&gt;Flask&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Build &lt;strong&gt;Docker images&lt;/strong&gt; and push them to the &lt;strong&gt;Docker Hub&lt;/strong&gt; registry&lt;/li&gt;
&lt;li&gt;Orchestrate &lt;strong&gt;multi-container applications&lt;/strong&gt; with &lt;strong&gt;Docker Compose&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Replicate a &lt;strong&gt;production-like infrastructure&lt;/strong&gt; anywhere&lt;/li&gt;
&lt;li&gt;Define a &lt;strong&gt;continuous integration&lt;/strong&gt; workflow using &lt;strong&gt;GitHub Actions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ideally, you should have some experience with &lt;a href=&quot;https://realpython.com/learning-paths/become-python-web-developer/&quot;&gt;web development&lt;/a&gt; in Python, &lt;a href=&quot;https://realpython.com/learning-paths/test-your-python-apps/&quot;&gt;test automation&lt;/a&gt;, the use of &lt;a href=&quot;https://realpython.com/python-redis/&quot;&gt;Redis with Python&lt;/a&gt;, and source code version control with &lt;a href=&quot;https://realpython.com/python-git-github-intro/&quot;&gt;Git and GitHub&lt;/a&gt;. Previous exposure to &lt;a href=&quot;https://realpython.com/python-versions-docker/&quot;&gt;Docker&lt;/a&gt; would be a plus but isn’t necessary. You should also have a Git client and a GitHub account to follow along and replicate the steps of this tutorial.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This tutorial is loosely based on an older tutorial entitled &lt;em&gt;Docker in Action - Fitter, Happier, More Productive&lt;/em&gt;, which was written by &lt;a href=&quot;https://twitter.com/mikeherman&quot;&gt;Michael Herman&lt;/a&gt;, who presented his CI workflow at PyTennessee on February 8, 2015. You can view the corresponding &lt;a href=&quot;http://realpython.github.io/fitter-happier-docker/&quot;&gt;slides&lt;/a&gt; presented at the conference if you’re interested.&lt;/p&gt;
&lt;p&gt;Unfortunately, many of the tools described in the original tutorial are no longer supported or available for free. In this updated tutorial, you’ll use the latest tools and technologies, such as GitHub Actions.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;If you’d like to skip the initial steps of setting up Docker on your computer and building a sample web application, then jump straight to &lt;a href=&quot;#define-a-docker-based-continuous-integration-pipeline&quot;&gt;defining a continuous integration pipeline&lt;/a&gt;. Either way, you’ll want to download the supporting materials, which come with a finished Flask web application and the related resources that will help you follow along with this tutorial:&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 Download:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/docker-continuous-integration-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-docker-continuous-integration-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download your Flask application and related resources &lt;/a&gt; so you can define a continuous integration pipeline with Docker.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;get-an-overview-of-the-project-architecture&quot;&gt;Get an Overview of the Project Architecture&lt;a class=&quot;headerlink&quot; href=&quot;#get-an-overview-of-the-project-architecture&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;By the end of this tutorial, you’ll have a Flask web application for tracking page views stored persistently in a Redis data store. It’ll be a multi-container application orchestrated by Docker Compose that you’ll be able to build and test locally as well as in the cloud, paving the way for continuous integration:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/page_tracker_architecture.drawio_2.1c8cf20462ae.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/page_tracker_architecture.drawio_2.1c8cf20462ae.png&quot; width=&quot;3732&quot; height=&quot;1820&quot; srcset=&quot;https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/page_tracker_architecture.drawio_2.1c8cf20462ae.png&amp;amp;w=933&amp;amp;sig=2fe64f5d97071f1af2e53e4a16742a86112b0cdd 933w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/page_tracker_architecture.drawio_2.1c8cf20462ae.png&amp;amp;w=1244&amp;amp;sig=a4162ddeef1117e2db43e7a089d064423bd47608 1244w, https://robocrop.realpython.net/?url=https%3A//files.realpython.com/media/page_tracker_architecture.drawio_2.1c8cf20462ae.png&amp;amp;w=1866&amp;amp;sig=5e6661349a6595d9fece6e3e14cf931554478e82 1866w, https://files.realpython.com/media/page_tracker_architecture.drawio_2.1c8cf20462ae.png 3732w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;The Architecture of the Page Tracker Application&quot; data-asset=&quot;5029&quot;&gt;&lt;/a&gt;&lt;/figure&gt;

&lt;p&gt;The application consists of two Docker containers. The first container will run a Flask application on top of Gunicorn, responding to HTTP requests and updating the number of page views. The second container will run a Redis instance for storing page view data persistently in a local volume on the host machine.&lt;/p&gt;
&lt;p&gt;Docker is all that’s required to run this application, and you’ll set it up now.&lt;/p&gt;
&lt;h2 id=&quot;set-up-docker-on-your-computer&quot;&gt;Set Up Docker on Your Computer&lt;a class=&quot;headerlink&quot; href=&quot;#set-up-docker-on-your-computer&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Docker is an umbrella term that can have a few different meanings for different people depending on the context. For example, when someone refers to &lt;em&gt;docker&lt;/em&gt;, they can mean one of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Docker,_Inc.&quot;&gt;Docker, Inc.&lt;/a&gt;: The company behind the platform and the related tools&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Docker_(software)&quot;&gt;Docker&lt;/a&gt;: The open-source container platform&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/docker/cli&quot;&gt;Docker CLI&lt;/a&gt;: The &lt;code&gt;docker&lt;/code&gt; client command-line program&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.docker.com/engine/reference/commandline/dockerd/&quot;&gt;&lt;code&gt;dockerd&lt;/code&gt;&lt;/a&gt;: The Docker &lt;a href=&quot;https://en.wikipedia.org/wiki/Daemon_(computing)&quot;&gt;daemon&lt;/a&gt; that manages the containers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are also several tools and projects associated with the &lt;a href=&quot;https://www.docker.com/&quot;&gt;Docker&lt;/a&gt; platform, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Docker Compose&lt;/li&gt;
&lt;li&gt;Docker Desktop&lt;/li&gt;
&lt;li&gt;Docker Engine&lt;/li&gt;
&lt;li&gt;Docker Hub&lt;/li&gt;
&lt;li&gt;Docker Swarm Mode&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this tutorial, you’ll use all but the last one from the list above. By the way, don’t confuse the legacy &lt;a href=&quot;https://github.com/docker-archive/classicswarm&quot;&gt;Docker Classic Swarm&lt;/a&gt;, which was an external tool, with the &lt;a href=&quot;https://docs.docker.com/engine/swarm/&quot;&gt;Docker Swarm Mode&lt;/a&gt; built into the Docker Engine since version 1.12.&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 heard of &lt;a href=&quot;https://github.com/docker/machine&quot;&gt;Docker Machine&lt;/a&gt; and &lt;a href=&quot;https://github.com/docker-archive/toolbox&quot;&gt;Docker Toolbox&lt;/a&gt;. These are old tools that are no longer maintained.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The main problem that Docker solves is the ability to run applications anywhere in consistent and reproducible environments with little or no configuration. It can  package your application code, &lt;a href=&quot;https://en.wikipedia.org/wiki/Binary_file&quot;&gt;binaries&lt;/a&gt;, and dependencies, such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Runtime_system&quot;&gt;language runtimes&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Library_(computing)&quot;&gt;libraries&lt;/a&gt;, into a single &lt;a href=&quot;https://en.wikipedia.org/wiki/Artifact_(software_development)&quot;&gt;artifact&lt;/a&gt;. You’ll use Docker to simulate a hypothetical production environment on your local machine during development and on a &lt;a href=&quot;https://realpython.com/python-continuous-integration/&quot;&gt;continuous integration&lt;/a&gt; server.&lt;/p&gt;
&lt;p&gt;You have two choices for installing Docker:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.docker.com/engine/&quot;&gt;Docker Engine&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.docker.com/desktop/&quot;&gt;Docker Desktop&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you’re comfortable around the terminal and appreciate an extra level of control, then look no further than the open-source &lt;strong&gt;Docker Engine&lt;/strong&gt;, which provides the core runtime and the command-line interface for managing your containers. On the other hand, if you prefer a one-stop-shop solution with an intuitive graphical user interface, then you should consider &lt;strong&gt;Docker Desktop&lt;/strong&gt; instead.&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; Out of the box, the desktop application comes with &lt;a href=&quot;https://docs.docker.com/compose/&quot;&gt;Docker Compose&lt;/a&gt;, which you’ll need later on, when you’re &lt;a href=&quot;#orchestrate-containers-using-docker-compose&quot;&gt;orchestrating containers&lt;/a&gt; for continuous integration.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/docker-continuous-integration/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/docker-continuous-integration/ »&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 #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>Efficient String Concatenation in Python</title>
      <id>https://realpython.com/python-string-concatenation/</id>
      <link href="https://realpython.com/python-string-concatenation/"/>
      <updated>2023-05-03T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to concatenate strings in Python. You&#x27;ll use different tools and techniques for string concatenation, including the concatenation operators and the .join() method. You&#x27;ll also explore other tools that can also be handy for string concatenation in Python.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;&lt;strong&gt;String concatenation&lt;/strong&gt; is a common operation in programming. It involves joining two or more strings to create a single new string. You’ll find several tools and techniques for concatenating strings in Python, each with its own pros and cons.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll go through the most common tools and techniques for concatenating strings. You’ll also code examples for each of them, which will help you choose the best option for your specific problems.&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 what &lt;strong&gt;string concatenation&lt;/strong&gt; is and why it’s useful&lt;/li&gt;
&lt;li&gt;Concatenate two strings using the &lt;strong&gt;concatenation operators&lt;/strong&gt;, &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;+=&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Efficiently concatenate multiple strings using the &lt;strong&gt;&lt;code&gt;.join()&lt;/code&gt; method&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Explore alternative concatenation techniques like &lt;strong&gt;string literals&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;StringIO&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should have a basic understanding of Python, especially its built-in &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;string&lt;/a&gt; data type.&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 Download:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-string-concatenation-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-string-concatenation-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download your sample code&lt;/a&gt; to learn how to efficiently concatenate strings in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;doing-string-concatenation-with-pythons-plus-operator&quot;&gt;Doing String Concatenation With Python’s Plus Operator (&lt;code&gt;+&lt;/code&gt;)&lt;a class=&quot;headerlink&quot; href=&quot;#doing-string-concatenation-with-pythons-plus-operator&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;String concatenation&lt;/strong&gt; is a pretty common operation consisting of joining two or more strings together end to end to build a final string. Perhaps the quickest way to achieve concatenation is to take two separate strings and combine them with the plus operator (&lt;code&gt;+&lt;/code&gt;), which is known as the &lt;strong&gt;concatenation operator&lt;/strong&gt; in this context:&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;s2&quot;&gt;&quot;Hello, &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Pythonista!&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;Hello, Pythonista!&#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;head&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;String Concatenation &quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tail&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;is Fun in Python!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tail&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;String Concatenation is Fun in Python!&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Using the concatenation operator to join two strings provides a quick solution for concatenating only a few strings. &lt;/p&gt;
&lt;p&gt;For a more realistic example, say you have an output line that will &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;print&lt;/a&gt; an informative message based on specific criteria. The beginning of the message might always be the same. However, the end of the message will vary depending on different criteria. In this situation, you can take advantage of the concatenation operator:&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;age_group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&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;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;a Child!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18&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;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;an Adolescent!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;65&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;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;an Adult!&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;in your Golden Years!&quot;&lt;/span&gt;
&lt;span class=&quot;hll&quot;&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 are &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;age_group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;29&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;You are an Adult!&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;age_group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;You are an Adolescent!&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;age_group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;68&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;You are in your Golden Years!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the above example, &lt;code&gt;age_group()&lt;/code&gt; prints a final message constructed with a common prefix and the string resulting from the &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;conditional statement&lt;/a&gt;. In this type of use case, the plus operator is your best option for quick string concatenation in Python.&lt;/p&gt;
&lt;p&gt;The concatenation operator has an augmented version that provides a shortcut for concatenating two strings together. The &lt;strong&gt;augmented concatenation operator&lt;/strong&gt; (&lt;code&gt;+=&lt;/code&gt;) has the following syntax:&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;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;other_string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This expression will concatenate the content of &lt;code&gt;string&lt;/code&gt; with the content of &lt;code&gt;other_string&lt;/code&gt;. It’s equivalent to saying &lt;code&gt;string = string + other_string&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here’s a short example of how the augmented concatenation operator works in practice:&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;word&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Py&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;tho&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;nis&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ta&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;word&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;Pythonista&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this example, every &lt;a href=&quot;https://realpython.com/python-assignment-operator/#augmented-assignments-for-concatenation-and-repetition&quot;&gt;augmented assignment&lt;/a&gt; adds a new syllable to the final word using the &lt;code&gt;+=&lt;/code&gt; operator. This concatenation technique can be useful when you have several strings in a &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;list&lt;/a&gt; or any other &lt;a href=&quot;https://realpython.com/python-iterators-iterables/#getting-to-know-python-iterables&quot;&gt;iterable&lt;/a&gt; and want to concatenate them in a &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt;:&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;concatenate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iterable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sep&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;sentence&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterable&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;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterable&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;n&quot;&gt;sentence&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sep&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;word&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;sentence&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;n&quot;&gt;concatenate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;I&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;am&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Pythonista!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;Hello, World! I am a Pythonista!&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Inside the loop, you use the augmented concatenation operator to quickly concatenate several strings in a loop. &lt;a href=&quot;#efficiently-concatenating-many-strings-with-join-in-python&quot;&gt;Later&lt;/a&gt; you’ll learn about &lt;code&gt;.join()&lt;/code&gt;, which is an even better way to concatenate a list of strings.&lt;/p&gt;
&lt;p&gt;Python’s concatenation operators can only concatenate string objects. If you use them with a different data type, then you get a &lt;a href=&quot;https://realpython.com/python-traceback/#typeerror&quot;&gt;&lt;code&gt;TypeError&lt;/code&gt;&lt;/a&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;s2&quot;&gt;&quot;The result is: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;TypeError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;can only concatenate str (not &quot;int&quot;) to str&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Your favorite fruits are: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;apple&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;grape&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;TypeError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;can only concatenate str (not &quot;list&quot;) to str&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/python-string-concatenation/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-string-concatenation/ »&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>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>Python Basics: Installing Packages With pip</title>
      <id>https://realpython.com/courses/python-pip-install/</id>
      <link href="https://realpython.com/courses/python-pip-install/"/>
      <updated>2023-04-18T14:00:00+00:00</updated>
      <summary>Python&#x27;s standard library includes a whole buffet of useful packages, but sometimes you need to reach for a third-party library. That&#x27;s where pip comes in handy. In this video course, you&#x27;ll learn how to pip install packages.</summary>
      <content type="html">
        &lt;p&gt;So far on the &lt;a href=&quot;https://realpython.com/learning-paths/python-basics/&quot;&gt;Python Basics learning path&lt;/a&gt;, you&amp;rsquo;ve been working within the bounds of the Python standard library. Now it&amp;rsquo;s time to unlock packages that aren&amp;rsquo;t included with Python by default. To do that, you&amp;rsquo;ll need &lt;strong&gt;&lt;code&gt;pip&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Many programming languages offer a &lt;strong&gt;package manager&lt;/strong&gt; that automates the process of installing, upgrading, and removing &lt;strong&gt;third-party packages&lt;/strong&gt;. Python is no exception. The de facto package manager for Python is called &lt;code&gt;pip&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Install&lt;/strong&gt; and &lt;strong&gt;manage&lt;/strong&gt; third-party packages with &lt;code&gt;pip&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;virtual environments&lt;/strong&gt; to separate project dependencies&lt;/li&gt;
&lt;li&gt;Declare &lt;strong&gt;requirements&lt;/strong&gt; and &lt;strong&gt;re-create&lt;/strong&gt; a development environment&lt;/li&gt;
&lt;li&gt;Navigate &lt;strong&gt;PyPI&lt;/strong&gt;, the Python Package Index&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With that knowledge as your guide, you&amp;rsquo;ll be able to confidently install packages to suit your programming needs.&lt;/p&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;. 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.&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>Using OrderedDict in Python</title>
      <id>https://realpython.com/courses/ordereddict-python/</id>
      <link href="https://realpython.com/courses/ordereddict-python/"/>
      <updated>2023-04-11T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn what Python&#x27;s OrderedDict is and how to use it in your code. You&#x27;ll also learn about the main differences between regular dictionaries and ordered dictionaries.</summary>
      <content type="html">
        &lt;p&gt;Sometimes you need a Python &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt; that remembers the order of its items. In the past, you had only one tool for solving this specific problem: Python&amp;rsquo;s &lt;a href=&quot;https://docs.python.org/3/library/collections.html#collections.OrderedDict&quot;&gt;&lt;code&gt;OrderedDict&lt;/code&gt;&lt;/a&gt;. It&amp;rsquo;s a dictionary subclass specially designed to remember the order of items, which is defined by the insertion order of keys.&lt;/p&gt;
&lt;p&gt;This changed in Python 3.6. The built-in &lt;code&gt;dict&lt;/code&gt; class now keeps its items ordered as well. Because of that, many in the Python community now wonder if &lt;code&gt;OrderedDict&lt;/code&gt; is still useful. A closer look at &lt;code&gt;OrderedDict&lt;/code&gt; will uncover that this class still provides valuable features.&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;Create and use &lt;strong&gt;&lt;code&gt;OrderedDict&lt;/code&gt; objects&lt;/strong&gt; in your code&lt;/li&gt;
&lt;li&gt;Identify the &lt;strong&gt;differences&lt;/strong&gt; between &lt;code&gt;OrderedDict&lt;/code&gt; and &lt;code&gt;dict&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Understand the &lt;strong&gt;pros&lt;/strong&gt; and &lt;strong&gt;cons&lt;/strong&gt; of using &lt;code&gt;OrderedDict&lt;/code&gt; vs &lt;code&gt;dict&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With this knowledge, you&amp;rsquo;ll able to choose the dictionary class that best fits your needs when you want to preserve the order of items.&lt;/p&gt;
&lt;p&gt;By the end of the course, you&amp;rsquo;ll see an example of implementing a dictionary-based queue using &lt;code&gt;OrderedDict&lt;/code&gt;, which would be more challenging if you used a regular &lt;code&gt;dict&lt;/code&gt; object.&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>
  
    <entry>
      <title>Check if a Python String Contains a Substring</title>
      <id>https://realpython.com/courses/python-string-contains-substring/</id>
      <link href="https://realpython.com/courses/python-string-contains-substring/"/>
      <updated>2023-04-04T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn the best way to check whether a Python string contains a substring. You&#x27;ll also learn about idiomatic ways to inspect the substring further, match substrings with conditions using regular expressions, and search for substrings in pandas.</summary>
      <content type="html">
        &lt;p&gt;If you&amp;rsquo;re new to programming or come from a programming language other than Python, you may be looking for the best way to check whether a string contains another string in Python.&lt;/p&gt;
&lt;p&gt;Identifying such &lt;a href=&quot;https://en.wikipedia.org/wiki/Substring&quot;&gt;substrings&lt;/a&gt; comes in handy when you&amp;rsquo;re working with &lt;a href=&quot;https://realpython.com/read-write-files-python/&quot;&gt;text content from a file&lt;/a&gt; or after you&amp;rsquo;ve &lt;a href=&quot;https://realpython.com/python-input-output/&quot;&gt;received user input&lt;/a&gt;. You may want to perform different actions in your program depending on whether a substring is present or not.&lt;/p&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll focus on the most Pythonic way to tackle this task, using the &lt;strong&gt;membership operator &lt;code&gt;in&lt;/code&gt;&lt;/strong&gt;. Additionally, you&amp;rsquo;ll learn how to &lt;strong&gt;identify the right string methods&lt;/strong&gt; for related, but different, use cases.&lt;/p&gt;
&lt;p&gt;Finally, you&amp;rsquo;ll also learn how to &lt;strong&gt;find substrings in pandas columns&lt;/strong&gt;. This is helpful if you need to search through data from a CSV file.&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 #151: Evaluating Python Packages &amp; Celebrating 20 Years of PyCon US</title>
      <id>https://realpython.com/podcasts/rpp/151/</id>
      <link href="https://realpython.com/podcasts/rpp/151/"/>
      <updated>2023-03-31T12:00:00+00:00</updated>
      <summary>Have you ever installed a Python package without knowing anything about it? What best practices should you employ to ensure the quality of your next package installation? Christopher Trudeau is back this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects. We also have Python Software Foundation executive director, Deb Nicholson, to share details about PyCon US 2023.</summary>
      <content type="html">
        &lt;p&gt;Have you ever installed a Python package without knowing anything about it? What best practices should you employ to ensure the quality of your next package installation? Christopher Trudeau is back this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects. We also have Python Software Foundation executive director, Deb Nicholson, to share details about PyCon US 2023.&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>YAML: Python&#x27;s Missing Battery</title>
      <id>https://realpython.com/courses/yaml-python/</id>
      <link href="https://realpython.com/courses/yaml-python/"/>
      <updated>2023-03-28T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn about working with YAML in Python. By the end of it, you&#x27;ll know about the available libraries, their strengths and weaknesses, and the advanced and potentially dangerous features of YAML.</summary>
      <content type="html">
        &lt;p&gt;Python is often marketed as a &lt;em&gt;batteries-included&lt;/em&gt; language because it comes with almost everything you&amp;rsquo;d ever expect from a programming language. This statement is mostly true, as the standard library and the external modules cover a broad spectrum of programming needs. However, Python lacks built-in support for the &lt;strong&gt;YAML data format&lt;/strong&gt;, commonly used for configuration and serialization.&lt;/p&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll learn how to work with YAML in Python using the available third-party libraries, with a focus on &lt;strong&gt;PyYAML&lt;/strong&gt;. If you&amp;rsquo;re new to YAML or haven&amp;rsquo;t used it in a while, then you&amp;rsquo;ll have a chance to take a quick crash course before diving deeper into the topic.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Read&lt;/strong&gt; and &lt;strong&gt;write&lt;/strong&gt; YAML documents in Python&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Serialize&lt;/strong&gt; Python&amp;rsquo;s &lt;strong&gt;built-in&lt;/strong&gt; and &lt;strong&gt;custom&lt;/strong&gt; data types to YAML&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Safely&lt;/strong&gt; read YAML documents from &lt;strong&gt;untrusted sources&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Notably, you&amp;rsquo;ll learn about YAML&amp;rsquo;s advanced, potentially dangerous features and how to protect yourself from them.&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 #150: Lessons Learned From Four Years Programming With Python</title>
      <id>https://realpython.com/podcasts/rpp/150/</id>
      <link href="https://realpython.com/podcasts/rpp/150/"/>
      <updated>2023-03-24T12:00:00+00:00</updated>
      <summary>What are the core lessons you&#x27;ve learned along your Python development journey? What are key takeaways you would share with new users of the language? This week on the show, Duarte Oliveira e Carmo is here to discuss his recent talk, &quot;Four Years of Python.&quot;</summary>
      <content type="html">
        &lt;p&gt;What are the core lessons you&#x27;ve learned along your Python development journey? What are key takeaways you would share with new users of the language? This week on the show, Duarte Oliveira e Carmo is here to discuss his recent talk, &quot;Four Years of Python.&quot;&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #149: Coding With namedtuple &amp; Python&#x27;s Dynamic Superpowers</title>
      <id>https://realpython.com/podcasts/rpp/149/</id>
      <link href="https://realpython.com/podcasts/rpp/149/"/>
      <updated>2023-03-17T12:00:00+00:00</updated>
      <summary>Have you explored Python&#x27;s collections module? Within it, you&#x27;ll find a powerful factory function called namedtuple(), which provides multiple enhancements over the standard tuple for writing clearer and cleaner 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;Have you explored Python&#x27;s collections module? Within it, you&#x27;ll find a powerful factory function called namedtuple(), which provides multiple enhancements over the standard tuple for writing clearer and cleaner 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>
  

</feed>
