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

  
    <entry>
      <title>Working With Global Variables in Python Functions</title>
      <id>https://realpython.com/courses/global-variables-in-python-functions/</id>
      <link href="https://realpython.com/courses/global-variables-in-python-functions/"/>
      <updated>2024-04-30T14:00:00+00:00</updated>
      <summary>In this video course, 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;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&amp;rsquo;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 video course, you&amp;rsquo;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;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 unittest: Writing Unit Tests for Your Code</title>
      <id>https://realpython.com/python-unittest/</id>
      <link href="https://realpython.com/python-unittest/"/>
      <updated>2024-04-29T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use the unittest framework to create unit tests for your Python code. Along the way, you&#x27;ll also learn how to create test cases, fixtures, test suites, and more.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;The Python &lt;a href=&quot;https://docs.python.org/3/library/index.html&quot;&gt;standard library&lt;/a&gt; ships with a testing framework named &lt;strong&gt;&lt;code&gt;unittest&lt;/code&gt;&lt;/strong&gt;, which you can use to write automated tests for your code. The &lt;code&gt;unittest&lt;/code&gt; package has an object-oriented approach where test cases derive from a base class, which has several useful methods.&lt;/p&gt;
&lt;p&gt;The framework supports many features that will help you write consistent unit tests for your code. These features include test cases, fixtures, test suites, and test discovery capabilities.&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;Write &lt;code&gt;unittest&lt;/code&gt; tests with the &lt;strong&gt;&lt;code&gt;TestCase&lt;/code&gt;&lt;/strong&gt; class&lt;/li&gt;
&lt;li&gt;Explore the &lt;strong&gt;assert&lt;/strong&gt; methods that &lt;code&gt;TestCase&lt;/code&gt; provides&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;unittest&lt;/code&gt; from the &lt;strong&gt;command line&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Group test cases using the &lt;strong&gt;&lt;code&gt;TestSuite&lt;/code&gt;&lt;/strong&gt; class&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;fixtures&lt;/strong&gt; to handle &lt;strong&gt;setup&lt;/strong&gt; and &lt;strong&gt;teardown&lt;/strong&gt; logic&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should be familiar with some important Python concepts, such as &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;inheritance&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-assert-statement/&quot;&gt;assertions&lt;/a&gt;. Having a good understanding of code &lt;a href=&quot;https://realpython.com/python-testing/&quot;&gt;testing&lt;/a&gt; is a plus.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-unittest-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-unittest-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to use Python’s unittest to write tests for your code.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Python&#x27;s unittest: Writing Unit Tests for Your Code” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-unittest/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #aadfe5;&quot; alt=&quot;Python&#x27;s unittest: Writing Unit Tests for Your Code&quot; src=&quot;https://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-unittest_Watermarked.f6549bba7422.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-unittest/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python&#x27;s unittest: Writing Unit Tests for Your Code&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of Python testing with the unittest framework from the standard library. With this knowledge, you&#x27;ll be able to create basic tests, execute them, and find bugs before your users do.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;testing-your-python-code&quot;&gt;Testing Your Python Code&lt;a class=&quot;headerlink&quot; href=&quot;#testing-your-python-code&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Code testing&lt;/strong&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Software_testing&quot;&gt;software testing&lt;/a&gt; is a fundamental part of a modern software development cycle. Through code testing, you can verify that a given software project works as expected and fulfills its requirements. Testing enforces code quality and robustness.&lt;/p&gt;
&lt;p&gt;You’ll do code testing during the development stage of an application or project. You’ll write tests that isolate sections of your code and verify its correctness. A well-written battery or suite of tests can also serve as documentation for the project at hand.&lt;/p&gt;
&lt;p&gt;You’ll find several different concepts and techniques around testing. Most of them surpass the scope of this tutorial. However, &lt;a href=&quot;https://en.wikipedia.org/wiki/Unit_testing&quot;&gt;unit test&lt;/a&gt; is an important and relevant concept. A unit test is a test that operates on an individual unit of software. A unit test aims to validate that the tested unit works as designed.&lt;/p&gt;
&lt;p&gt;A &lt;strong&gt;unit&lt;/strong&gt; is often a small part of a program that takes a few inputs and produces an output. &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-classes/#providing-behavior-with-methods&quot;&gt;methods&lt;/a&gt;, and other &lt;a href=&quot;https://realpython.com/python-callable-instances/&quot;&gt;callables&lt;/a&gt; are good examples of units that you’d need to test.&lt;/p&gt;
&lt;p&gt;In Python, there are several tools to help you write, organize, run, and automate your unit test. In the Python &lt;a href=&quot;https://docs.python.org/3/library/index.html&quot;&gt;standard library&lt;/a&gt;, you’ll find two of these tools:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;doctest&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;unittest&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Python’s &lt;code&gt;doctest&lt;/code&gt; module is a lightweight &lt;a href=&quot;https://en.wikipedia.org/wiki/Test_automation#Framework_approach_in_automation&quot;&gt;testing framework&lt;/a&gt; that provides quick and straightforward &lt;a href=&quot;https://en.wikipedia.org/wiki/Test_automation&quot;&gt;test automation&lt;/a&gt;. It can read the test cases from your project’s documentation and your code’s docstrings. This framework is shipped with the Python interpreter as part of the batteries-included philosophy.&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 dive deeper into &lt;code&gt;doctest&lt;/code&gt;, check out the &lt;a href=&quot;https://realpython.com/python-doctest/&quot;&gt;Python’s doctest: Document and Test Your Code at Once&lt;/a&gt; tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;unittest&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-modules-packages/#python-packages&quot;&gt;package&lt;/a&gt; is also a testing framework. However, it provides a more complete solution than &lt;code&gt;doctest&lt;/code&gt;. In the following sections, you’ll learn and work with &lt;a href=&quot;https://docs.python.org/3/library/unittest.html#module-unittest&quot;&gt;&lt;code&gt;unittest&lt;/code&gt;&lt;/a&gt; to create suitable unit tests for your Python code.&lt;/p&gt;
&lt;h2 id=&quot;getting-to-know-pythons-unittest&quot;&gt;Getting to Know Python’s &lt;code&gt;unittest&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-pythons-unittest&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;unittest&lt;/code&gt; package provides a unit test framework inspired by &lt;a href=&quot;https://en.wikipedia.org/wiki/JUnit&quot;&gt;JUnit&lt;/a&gt;, which is a unit test framework for the &lt;a href=&quot;https://realpython.com/java-vs-python/&quot;&gt;Java&lt;/a&gt; language. The &lt;code&gt;unittest&lt;/code&gt; framework is directly available in the standard library, so you don’t have to install anything to use this tool.&lt;/p&gt;
&lt;p&gt;The framework uses an &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented&lt;/a&gt; approach and supports some essential concepts that facilitate test creation, organization, preparation, and automation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Test case&lt;/strong&gt;: An individual unit of testing. It examines the output for a given input set.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test suite&lt;/strong&gt;: A collection of test cases, test suites, or both. They’re grouped and executed as a whole.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test fixture&lt;/strong&gt;: A group of actions required to set up an environment for testing. It also includes the teardown processes after the tests run.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test runner&lt;/strong&gt;: A component that handles the execution of tests and communicates the results to the user.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the following sections, you’ll dive into using the &lt;code&gt;unittest&lt;/code&gt; package to create test cases, suites of tests, fixtures, and, of course, run your tests.&lt;/p&gt;
&lt;h2 id=&quot;organizing-your-tests-with-the-testcase-class&quot;&gt;Organizing Your Tests With the &lt;code&gt;TestCase&lt;/code&gt; Class&lt;a class=&quot;headerlink&quot; href=&quot;#organizing-your-tests-with-the-testcase-class&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;unittest&lt;/code&gt; package defines the &lt;code&gt;TestCase&lt;/code&gt; class, which is primarily designed for writing unit tests. To start writing your test cases, you just need to import the class and subclass it. Then, you’ll add methods whose names should begin with &lt;code&gt;test&lt;/code&gt;. These methods will test a given unit of code using different inputs and check for the expected results.&lt;/p&gt;
&lt;p&gt;Here’s a quick test case that tests 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; function:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-unittest/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-unittest/ »&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 #202: Pydantic Data Validation &amp; Python Web Security Practices</title>
      <id>https://realpython.com/podcasts/rpp/202/</id>
      <link href="https://realpython.com/podcasts/rpp/202/"/>
      <updated>2024-04-26T12:00:00+00:00</updated>
      <summary>How do you verify and validate the data coming into your Python web application? What tools and security best practices should you consider as a developer? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;How do you verify and validate the data coming into your Python web application? What tools and security best practices should you consider as a developer? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: What Is the __pycache__ Folder in Python?</title>
      <id>https://realpython.com/quizzes/python-pycache/</id>
      <link href="https://realpython.com/quizzes/python-pycache/"/>
      <updated>2024-04-26T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll have the opportunity to test your knowledge of the __pycache__ folder, including when, where, and why Python creates these folders.</summary>
      <content type="html">
        &lt;p&gt;As your Python project grows, you typically organize your code in modules and packages for easier maintenance and reusability. When you do that, you&amp;rsquo;ll likely notice the sudden emergence of a &lt;code&gt;__pycache__&lt;/code&gt; folder alongside your original files, popping up in various locations unexpectedly.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>What&#x27;s Lazy Evaluation in Python?</title>
      <id>https://realpython.com/python-lazy-evaluation/</id>
      <link href="https://realpython.com/python-lazy-evaluation/"/>
      <updated>2024-04-24T14:00:00+00:00</updated>
      <summary>This tutorial explores lazy evaluation in Python and looks at the advantages and disadvantages of using lazy and eager evaluation methods. By the end of this tutorial, you&#x27;ll clearly understand which approach is best for you, depending on your needs.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Being lazy is not always a bad thing. Every line of code you write has at least one expression that Python needs to evaluate. Python lazy evaluation is when Python takes the lazy option and delays working out the value returned by an expression until that value is needed.&lt;/p&gt;
&lt;p&gt;An &lt;strong&gt;expression&lt;/strong&gt; in Python is a unit of code that evaluates to a value. Examples of expressions include object names, function calls, expressions with arithmetic operators, literals that create built-in object types such as lists, and more. However, not all statements are expressions. For example, &lt;code&gt;if&lt;/code&gt; statements and &lt;code&gt;for&lt;/code&gt; loop statements don’t return a value.&lt;/p&gt;
&lt;p&gt;Python needs to evaluate every expression it encounters to use its value. In this tutorial, you’ll learn about the different ways Python evaluates these expressions. You’ll understand why some expressions are evaluated immediately, while others are evaluated later in the program’s execution. So, &lt;strong&gt;what’s lazy evaluation in Python?&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-lazy-evaluation-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-lazy-evaluation-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to use lazy evaluation in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “What&#x27;s Lazy Evaluation in Python?” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-lazy-evaluation/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #ffc873;&quot; alt=&quot;What&#x27;s Lazy Evaluation in Python?&quot; src=&quot;https://files.realpython.com/media/Eager-vs-Lazy-Evaluation-in-Python-Pros-and-Cons_Watermarked.15b852ab57a6.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Eager-vs-Lazy-Evaluation-in-Python-Pros-and-Cons_Watermarked.15b852ab57a6.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Eager-vs-Lazy-Evaluation-in-Python-Pros-and-Cons_Watermarked.15b852ab57a6.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Eager-vs-Lazy-Evaluation-in-Python-Pros-and-Cons_Watermarked.15b852ab57a6.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Eager-vs-Lazy-Evaluation-in-Python-Pros-and-Cons_Watermarked.15b852ab57a6.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-lazy-evaluation/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;What&#x27;s Lazy Evaluation in Python?&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of the differences between lazy and eager evaluation in Python. By working through this quiz, you&#x27;ll revisit how Python optimizes memory use and computational overhead by deciding when to compute values.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;in-short-python-lazy-evaluation-generates-objects-only-when-needed&quot;&gt;In Short: Python Lazy Evaluation Generates Objects Only When Needed&lt;a class=&quot;headerlink&quot; href=&quot;#in-short-python-lazy-evaluation-generates-objects-only-when-needed&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;An expression evaluates to a value. However, you can separate the type of evaluation of expressions into two types:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Eager evaluation&lt;/li&gt;
&lt;li&gt;Lazy evaluation&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Eager evaluation&lt;/strong&gt; refers to those cases when Python evaluates an expression as soon as it encounters it. Here are some examples of expressions that are evaluated eagerly:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;linenos&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;15&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 3&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;random&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&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;random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randint&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;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 6&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 7&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 8&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 9&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;[2, 4, 6, 8, 10]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;10&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;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;[2, 4, 6, 8, 10]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Interactive environments, such as the &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;standard Python REPL&lt;/a&gt; used in this example, display the value of an expression when the line only contains the expression. This code section shows a few examples of statements and expressions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Lines 1 and 2&lt;/strong&gt;: The first example includes the addition operator &lt;code&gt;+&lt;/code&gt;, which Python evaluates as soon as it encounters it. The REPL shows the value &lt;code&gt;15&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lines 4 to 6&lt;/strong&gt;: The second example includes two lines:&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;import statement&lt;/strong&gt; includes the keyword &lt;code&gt;import&lt;/code&gt; followed by the name of a module. The module name &lt;code&gt;random&lt;/code&gt; is evaluated eagerly. &lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;function call &lt;code&gt;random.randint()&lt;/code&gt;&lt;/strong&gt; is evaluated eagerly, and its value is returned immediately. All standard functions are evaluated eagerly. You’ll learn about generator functions later, which behave differently.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lines 8 to 12&lt;/strong&gt;: The final example has three lines of code:&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;literal to create a list&lt;/strong&gt; is an expression that’s evaluated eagerly. This expression contains several integer literals, which are themselves expressions evaluated immediately.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;assignment statement&lt;/strong&gt; assigns the object created by the list literal to the name &lt;code&gt;numbers&lt;/code&gt;. This statement is not an expression and doesn’t return a value. However, it includes the list literal on the right-hand side, which is an expression that’s evaluated eagerly.&lt;/li&gt;
&lt;li&gt;The final line contains &lt;strong&gt;the name &lt;code&gt;numbers&lt;/code&gt;,&lt;/strong&gt; which is eagerly evaluated to return the list object.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The list you create in the final example is created in full when you define it. Python needs to allocate memory for the list and all its elements. This memory won’t be freed as long as this list exists in your program. The memory allocation in this example is small and won’t impact the program. However, larger objects require more memory, which can cause performance issues.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Lazy_evaluation&quot;&gt;Lazy evaluation&lt;/a&gt;&lt;/strong&gt; refers to cases when Python doesn’t work out the values of an expression immediately. Instead, the values are returned at the point when they’re required in the program. Lazy evaluation can also be referred to as &lt;em&gt;call-by-need&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;This delay of when the program evaluates an expression delays the use of resources to create the value, which can improve the performance of a program by spreading the time-consuming process across a longer time period. It also prevents values that will not be used in the program from being generated. This can occur when the program terminates or moves to another part of its execution before all the generated values are used. &lt;/p&gt;
&lt;p&gt;When large datasets are created using lazily-evaluated expressions, the program doesn’t need to use memory to store the data structure’s contents. The values are only generated when they’re needed.&lt;/p&gt;
&lt;p&gt;An example of lazy evaluation occurs within the &lt;code&gt;for&lt;/code&gt; loop when you iterate using &lt;code&gt;range()&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000_001&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This is iteration &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;a href=&quot;https://realpython.com/python-range/&quot;&gt;built-in &lt;code&gt;range()&lt;/code&gt;&lt;/a&gt; is the constructor for Python’s &lt;code&gt;range&lt;/code&gt; object. The &lt;code&gt;range&lt;/code&gt; object does not store all of the one million integers it represents. Instead, the &lt;code&gt;for&lt;/code&gt; loop creates a &lt;code&gt;range_iterator&lt;/code&gt; from the &lt;code&gt;range&lt;/code&gt; object, which generates the next number in the sequence when it’s needed. Therefore, the program never needs to have all the values stored in memory at the same time.&lt;/p&gt;
&lt;p&gt;Lazy evaluation also allows you to create infinite data structures, such as a live stream of audio or video data that continuously updates with new information, since the program doesn’t need to store all the values in memory at the same time. Infinite data structures are not possible with eager evaluation since they can’t be stored in memory.&lt;/p&gt;
&lt;p&gt;There are disadvantages to deferred evaluation. Any errors raised by an expression are also deferred to a later point in the program. This delay can make debugging harder.&lt;/p&gt;
&lt;p&gt;The lazy evaluation of the integers represented by &lt;code&gt;range()&lt;/code&gt; in a &lt;code&gt;for&lt;/code&gt; loop is one example of lazy evaluation. You’ll learn about more examples in the following section of this tutorial.&lt;/p&gt;
&lt;h2 id=&quot;what-are-examples-of-lazy-evaluation-in-python&quot;&gt;What Are Examples of Lazy Evaluation in Python?&lt;a class=&quot;headerlink&quot; href=&quot;#what-are-examples-of-lazy-evaluation-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In the previous section, you learned about using &lt;code&gt;range()&lt;/code&gt; in a &lt;code&gt;for&lt;/code&gt; loop, which leads to lazy evaluation of the integers represented by the &lt;code&gt;range&lt;/code&gt; object. There are other expressions in Python that lead to lazy evaluation. In this section, you’ll explore the main ones.&lt;/p&gt;
&lt;h3 id=&quot;other-built-in-data-types&quot;&gt;Other Built-In Data Types&lt;a class=&quot;headerlink&quot; href=&quot;#other-built-in-data-types&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-lazy-evaluation/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-lazy-evaluation/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Basics Exercises: Scopes</title>
      <id>https://realpython.com/courses/python-basics-exercises-scopes/</id>
      <link href="https://realpython.com/courses/python-basics-exercises-scopes/"/>
      <updated>2024-04-23T14:00:00+00:00</updated>
      <summary>In this Python Basics Exercises course, you&#x27;ll practice working with scope in Python. You&#x27;ll reinforce important coding concepts by working with variables inside and outside of functions and loops. You&#x27;ll also get to practice the LEGB rule.</summary>
      <content type="html">
        &lt;p&gt;On your Python journey, you&amp;rsquo;ve worked with &lt;a href=&quot;https://realpython.com/courses/python-basics-functions-loops/&quot;&gt;functions and loops&lt;/a&gt;. To fully understand functions and loops in Python, you need to be familiar with the issue of scope.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this Python Basics Exercises video course, you&amp;rsquo;ll practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Identifying the &lt;strong&gt;scope&lt;/strong&gt; of objects&lt;/li&gt;
&lt;li&gt;Working with the &lt;code&gt;global&lt;/code&gt; keyword&lt;/li&gt;
&lt;li&gt;Exploring the &lt;strong&gt;LEGB rule&lt;/strong&gt; for scope resolution&lt;/li&gt;
&lt;li&gt;Using the &lt;code&gt;return&lt;/code&gt; statement in a function&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Scope can be one of the more difficult programming concepts to understand, so in this video course, you&amp;rsquo;ll get additional practice working with it.&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;. You can also check out the other &lt;a href=&quot;https://realpython.com/learning-paths/python-basics/&quot;&gt;Python Basics courses&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Note that you&amp;rsquo;ll be using &lt;a href=&quot;https://realpython.com/python-idle/&quot;&gt;IDLE&lt;/a&gt; to &lt;a href=&quot;https://realpython.com/interacting-with-python/&quot;&gt;interact with Python&lt;/a&gt; throughout this course. If you&amp;rsquo;re just getting started, then you might want to check out &lt;a href=&quot;https://realpython.com/courses/setting-up-python/&quot;&gt;Python Basics: Setting Up Python&lt;/a&gt; before diving into this course.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python Sequences: A Comprehensive Guide</title>
      <id>https://realpython.com/quizzes/python-sequences/</id>
      <link href="https://realpython.com/quizzes/python-sequences/"/>
      <updated>2024-04-23T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of sequences in Python. You&#x27;ll revisit the basic characteristics of a sequence, operations common to most sequences, special methods associated with sequences, and how to create user-defined mutable and immutable sequences.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;Python sequences&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit the basic characteristics of a sequence, operations common to most sequences, special methods associated with sequences, and how to create user-defined mutable and immutable sequences.&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>Write Unit Tests for Your Python Code With ChatGPT</title>
      <id>https://realpython.com/chatgpt-unit-tests-python/</id>
      <link href="https://realpython.com/chatgpt-unit-tests-python/"/>
      <updated>2024-04-22T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use ChatGPT to generate tests for your Python code. You&#x27;ll use the chat to create doctest, unittest, and pytest tests for your code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Having a good battery of tests for your code may be a requirement for many Python projects. In practice, writing &lt;strong&gt;unit tests&lt;/strong&gt; is hard and can take a lot of time and effort. Therefore, some developers don’t like to write them. However, with &lt;strong&gt;large language models&lt;/strong&gt; (LLMs) and tools like &lt;strong&gt;ChatGPT&lt;/strong&gt;, you can quickly create robust and complete sets of tests for your Python code.&lt;/p&gt;
&lt;p&gt;In Python, you can use multiple different tools for writing tests. The most commonly used tools include &lt;code&gt;doctest&lt;/code&gt;, &lt;code&gt;unittest&lt;/code&gt;, and &lt;code&gt;pytest&lt;/code&gt;. ChatGPT can be of great help in writing tests with any of these tools.&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;Prompt ChatGPT to create tests using &lt;strong&gt;&lt;code&gt;doctest&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use ChatGPT to write &lt;strong&gt;&lt;code&gt;unittest&lt;/code&gt;&lt;/strong&gt; tests, fixtures, and suites&lt;/li&gt;
&lt;li&gt;Craft ChatGPT prompts to write &lt;strong&gt;&lt;code&gt;pytest&lt;/code&gt;&lt;/strong&gt; tests and fixtures&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;alternative prompts&lt;/strong&gt; for cases where the code isn’t available&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should &lt;a href=&quot;https://realpython.com/chatgpt-coding-mentor-python/#set-up-your-chatgpt-coding-mentor&quot;&gt;set up a ChatGPT account&lt;/a&gt; and know the basics of interacting with this tool using &lt;a href=&quot;https://realpython.com/practical-prompt-engineering/&quot;&gt;prompt engineering&lt;/a&gt;. You should also know the basics of how to &lt;a href=&quot;https://realpython.com/python-testing/&quot;&gt;test code&lt;/a&gt; in Python.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/chatgpt-unit-tests-python/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-chatgpt-unit-tests-python&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; you’ll use to write unit tests for your Python code using ChatGPT.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;benefits-of-using-chatgpt-for-testing-python-code&quot;&gt;Benefits of Using ChatGPT for Testing Python Code&lt;a class=&quot;headerlink&quot; href=&quot;#benefits-of-using-chatgpt-for-testing-python-code&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Having good and up-to-date &lt;a href=&quot;https://realpython.com/python-testing/#unit-tests-vs-integration-tests&quot;&gt;unit tests&lt;/a&gt; for your code is a must for any Python project. Poorly tested code or code without tests may end up being unreliable and weak. With automated tests, you can ensure and show that your code works correctly in different scenarios. So, having tests is important from the technical and commercial point of view.&lt;/p&gt;
&lt;p&gt;Writing good tests is hard and can take a lot of time. That’s why some developers don’t like to write them at all. Using &lt;a href=&quot;https://en.wikipedia.org/wiki/Large_language_model&quot;&gt;large language models (LLM)&lt;/a&gt; like &lt;a href=&quot;https://realpython.com/chatgpt-coding-mentor-python/&quot;&gt;ChatGPT&lt;/a&gt; can be a viable alternative for providing your projects and code with proper tests.&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 use ChatGPT and other LLMs in many useful ways in the context of Python development. Check out the following resources for other use cases and useful insights:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/chatgpt-coding-mentor-python/&quot;&gt;ChatGPT: Your Personal Python Coding Mentor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/podcasts/rpp/174/&quot;&gt;Episode 174: Considering ChatGPT’s Technical Review of a Programming Book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/document-python-code-with-chatgpt/&quot;&gt;Document Your Python Code and Projects With ChatGPT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/practical-prompt-engineering/&quot;&gt;Prompt Engineering: A Practical Example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/build-llm-rag-chatbot-with-langchain/&quot;&gt;Build an LLM RAG Chatbot With LangChain&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;Some of the benefits of using ChatGPT to write tests for your Python code include the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Efficiency and speed&lt;/strong&gt;: It can generate unit tests based on specifications or code snippets. This possibility significantly reduces the time that you need to spend writing tests. So you can focus on writing application logic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Coverage improvement&lt;/strong&gt;: It can suggest tests for edge cases or scenarios that developers might not immediately consider. This way, you can improve your code’s test &lt;a href=&quot;https://coverage.readthedocs.io/&quot;&gt;coverage&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error reduction&lt;/strong&gt;: It can reduce human error in writing repetitive or boilerplate test code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Learning and onboarding&lt;/strong&gt;: It can serve as an educational tool for developers who are new to testing frameworks or unfamiliar with best practices in unit testing. The generated tests can help developers learn about testing patterns, &lt;a href=&quot;https://realpython.com/python-assert-statement/&quot;&gt;assertions&lt;/a&gt;, and ways to effectively write tests.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With ChatGPT, you can generate unit tests for your Python code in almost no time. However, you must note that even though the generated tests can look good, you should still review and possibly refine the generated tests.&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 this tutorial, you’ll use a free ChatGPT account that’s powered by the GPT-3.5 LLM. You can use this model for free with the default &lt;a href=&quot;https://chat.openai.com/auth/login&quot;&gt;web interface&lt;/a&gt; by OpenAI. If you use a paid account with GPT-4, then your results might be more accurate and faster.&lt;/p&gt;
&lt;p&gt;Additionally, you’ll use an individual chat thread for each major section in the tutorial. So you’ll use different threads for the &lt;code&gt;doctest&lt;/code&gt;, &lt;code&gt;unittest&lt;/code&gt;, and &lt;code&gt;pytest&lt;/code&gt; sections.&lt;/p&gt;
&lt;p&gt;Using a single chat thread to run all the examples in this tutorial may cause the chat to generate significantly different responses because of the past context, which includes previous prompts and responses.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the following sections, you’ll learn the basics of using ChatGPT as an assistant for creating coherent unit tests for your Python projects using different test frameworks and libraries.&lt;/p&gt;
&lt;h2 id=&quot;writing-doctest-tests-with-chatgpt&quot;&gt;Writing &lt;code&gt;doctest&lt;/code&gt; Tests With ChatGPT&lt;a class=&quot;headerlink&quot; href=&quot;#writing-doctest-tests-with-chatgpt&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python’s &lt;a href=&quot;https://docs.python.org/3/library/doctest.html#module-doctest&quot;&gt;&lt;code&gt;doctest&lt;/code&gt;&lt;/a&gt; module provides a lightweight &lt;strong&gt;testing framework&lt;/strong&gt; that you can use for &lt;a href=&quot;https://en.wikipedia.org/wiki/Test_automation&quot;&gt;test automation&lt;/a&gt;. It can read the test cases from your project’s documentation and your code’s docstrings. This framework comes with the Python interpreter, so you’ll have it at your disposal with any Python installation, which is great.&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 dive deeper into how to use the &lt;code&gt;doctest&lt;/code&gt; module for testing your code, check out &lt;a href=&quot;https://realpython.com/python-doctest/&quot;&gt;Python’s &lt;code&gt;doctest&lt;/code&gt;: Document and Test Your Code at Once&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;With &lt;code&gt;doctest&lt;/code&gt;, you can write code that provides examples of how your code works, simulating &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;REPL&lt;/a&gt; sessions. These examples work as documentation and also as test cases or unit tests. Each &lt;code&gt;doctest&lt;/code&gt; test needs a statement or expression and an expected result.&lt;/p&gt;
&lt;p&gt;You can use ChatGPT to help you out with writing &lt;code&gt;doctest&lt;/code&gt; tests. First, you need some code to test. The following function tries to tackle the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fizz_buzz#Programming&quot;&gt;FizzBuzz&lt;/a&gt; challenge, where you return &lt;code&gt;&quot;fizz&quot;&lt;/code&gt; for numbers divisible by three, &lt;code&gt;&quot;buzz&quot;&lt;/code&gt; for those divisible by five, and &lt;code&gt;&quot;fizz buzz&quot;&lt;/code&gt; for those divisible by both three and five.&lt;/p&gt;
&lt;p&gt;Go ahead and create a &lt;code&gt;fizzbuzz.py&lt;/code&gt; file and add the following code to it:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    &lt;span class=&quot;mr-2&quot; aria-label=&quot;Filename&quot;&gt;&lt;code style=&quot;color: inherit;&quot;&gt;fizzbuzz.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fizzbuzz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&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;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;buzz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&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;15&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz buzz&quot;&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;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This function works okay for numbers divisible by &lt;code&gt;3&lt;/code&gt; or &lt;code&gt;5&lt;/code&gt;. However, there is a slight issue with numbers that are divisible by both. Even though you know this, go ahead and start a new chat thread. Then, prompt ChatGPT to write &lt;code&gt;doctest&lt;/code&gt; test for the function:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You:&lt;/strong&gt; Write &lt;code&gt;doctest&lt;/code&gt; tests for the following function:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fizzbuzz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&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;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;buzz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&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;15&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz buzz&quot;&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;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;ChatGPT:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Certainly! The function you’ve provided implements a basic FizzBuzz algorithm but with a slight logical error. The check for divisibility by &lt;code&gt;15&lt;/code&gt; should come before checks for &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt;, as every number divisible by &lt;code&gt;15&lt;/code&gt; is also divisible by both &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt;, but your current order will never reach the &lt;code&gt;&quot;fizz buzz&quot;&lt;/code&gt; case. Here’s a corrected version of your function with the logical order fixed, followed by &lt;code&gt;doctest&lt;/code&gt; tests for it:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fizzbuzz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Returns &#x27;fizz&#x27; if number is divisible by 3,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;buzz&#x27; if number is divisible by 5,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz buzz&#x27; if number is divisible by 15,&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    and the number itself otherwise.&lt;/span&gt;

&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(3)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(5)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(15)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(4)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    4&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(30)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(9)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(10)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(2)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    2&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz buzz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&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;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&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;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;buzz&quot;&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;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To use these &lt;code&gt;doctest&lt;/code&gt; tests, you’ll need to include them in the docstring of your function as shown above. Then, you can run the tests with the &lt;code&gt;doctest&lt;/code&gt; module by adding the following to your script:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;vm&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;doctest&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;doctest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testmod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This code will automatically run the tests defined in the docstrings when you execute the Python file. Remember, the corrected order of conditions in the function ensures that numbers divisible by both &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt; return &lt;code&gt;&quot;fizz buzz&quot;&lt;/code&gt;, which is crucial for the FizzBuzz logic.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Wow! That great! The chat not only wrote the &lt;code&gt;doctest&lt;/code&gt; tests for you. It also fixed the issue, explained important concepts around &lt;code&gt;doctest&lt;/code&gt;, and provided instructions on how to run the tests. Note that the tests cover both regular and edge cases, which is pretty convenient.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/chatgpt-unit-tests-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/chatgpt-unit-tests-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>The Real Python Podcast – Episode #201: Decoupling Systems to Get Closer to the Data</title>
      <id>https://realpython.com/podcasts/rpp/201/</id>
      <link href="https://realpython.com/podcasts/rpp/201/"/>
      <updated>2024-04-19T12:00:00+00:00</updated>
      <summary>What are the benefits of using a decoupled data processing system? How do you write reusable queries for a variety of backend data platforms? This week on the show, Phillip Cloud, the lead maintainer of Ibis, will discuss this portable Python dataframe library.</summary>
      <content type="html">
        &lt;p&gt;What are the benefits of using a decoupled data processing system? How do you write reusable queries for a variety of backend data platforms? This week on the show, Phillip Cloud, the lead maintainer of Ibis, will discuss this portable Python dataframe library.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python&#x27;s unittest: Writing Unit Tests for Your Code</title>
      <id>https://realpython.com/quizzes/python-unittest/</id>
      <link href="https://realpython.com/quizzes/python-unittest/"/>
      <updated>2024-04-19T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python testing with the unittest framework from the standard library. With this knowledge, you&#x27;ll be able to create basic tests, execute them, and find bugs before your users do.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of testing your Python code with the &lt;a href=&quot;https://realpython.com/python-unittest/&quot;&gt;unittest framework&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Testing in Python is a huge topic and can come with a lot of complexity, but it doesn&amp;rsquo;t need to be hard. You can create simple tests for your application in a few easy steps and then build on them from there.&lt;/p&gt;
&lt;p&gt;With this quiz, you can check your understanding of testing with Python&amp;rsquo;s &lt;code&gt;unittest&lt;/code&gt; framework. Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>How to Format Floats Within F-Strings in Python</title>
      <id>https://realpython.com/how-to-python-f-string-format-float/</id>
      <link href="https://realpython.com/how-to-python-f-string-format-float/"/>
      <updated>2024-04-17T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use Python format specifiers within an f-string to allow you to neatly format a float to your required precision.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;You’ll often need to format and round a Python &lt;a href=&quot;https://docs.python.org/3/library/functions.html#float&quot;&gt;&lt;code&gt;float&lt;/code&gt;&lt;/a&gt; to display the results of your calculations neatly within strings. In earlier versions of Python, this was a messy thing to do because you needed to round your numbers &lt;em&gt;first&lt;/em&gt; and then use either string concatenation or the &lt;a href=&quot;https://realpython.com/python-string-formatting/#1-old-style-string-formatting-operator&quot;&gt;old string formatting&lt;/a&gt; technique to do this for you. &lt;/p&gt;
&lt;p&gt;Since Python 3.6, the &lt;a href=&quot;https://peps.python.org/pep-0498/&quot;&gt;literal string interpolation&lt;/a&gt;, more commonly known as a &lt;strong&gt;formatted string literal&lt;/strong&gt; or &lt;strong&gt;&lt;a href=&quot;https://realpython.com/python-f-strings/&quot;&gt;f-string&lt;/a&gt;&lt;/strong&gt;, allows you to customize the content of your strings in a more readable way.&lt;/p&gt;
&lt;p&gt;An f-string is a literal string prefixed with a lowercase or uppercase letter &lt;code&gt;f&lt;/code&gt; and contains zero or more &lt;strong&gt;replacement fields&lt;/strong&gt; enclosed within a pair of curly braces &lt;code&gt;{...}&lt;/code&gt;. Each field contains an &lt;strong&gt;expression&lt;/strong&gt; that produces a value. You can calculate the field’s content, but you can also use function calls or even variables.&lt;/p&gt;
&lt;p&gt;While most strings have a constant value, f-strings are evaluated at runtime. This makes it possible for you to pass different data into the replacement fields of the same f-string and produce different output. This extensibility of f-strings makes them a great way to embed dynamic content neatly inside strings. However, even though f-strings have largely replaced the earlier methods, they do have their short-comings.&lt;/p&gt;
&lt;p&gt;For example, one of the most common attacks performed on a &lt;a href=&quot;https://en.wikipedia.org/wiki/Relational_database&quot;&gt;relational database&lt;/a&gt; is a &lt;a href=&quot;https://en.wikipedia.org/wiki/SQL_injection&quot;&gt;SQL injection&lt;/a&gt; attack. Often, users provide parameters to SQL queries, and if the query is formed within an f-string, it may be possible to damage a database by passing in rogue commands. F-strings can also be used in a &lt;a href=&quot;https://en.wikipedia.org/wiki/Denial-of-service_attack&quot;&gt;denial-of-service&lt;/a&gt; attack by attacking &lt;a href=&quot;https://realpython.com/python-logging/&quot;&gt;Python’s logging module&lt;/a&gt; code.&lt;/p&gt;
&lt;p&gt;In older versions of Python, f-strings had a number of &lt;a href=&quot;https://realpython.com/python312-f-strings/#f-strings-had-some-limitations-before-python-312&quot;&gt;other limitations&lt;/a&gt; that were only fixed with &lt;a href=&quot;https://realpython.com/python312-f-strings/&quot;&gt;Python version 3.12&lt;/a&gt;. This version is used throughout this tutorial.&lt;/p&gt;
&lt;p&gt;Take a look at the example below. It shows you how to embed the result of a calculation within an f-string:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;One third, expressed as a float is: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;One third, expressed as a float is: 0.3333333333333333&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Without any explicit rounding, once an expression has produced its value it’ll be inserted into the string using a default number of decimal places. Here, the result is shown to sixteen decimal places, which, in most cases, is more precision than you’ll ever need. So you’ll likely want to round your final answer to a more practical number of digits.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll learn how to use a Python f-string to format floats to meet your requirements.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/how-to-python-f-string-format-float-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-how-to-python-f-string-format-float-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code and exercise solutions &lt;/a&gt;you’ll use for learning how to format floats within f-strings in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Format Floats Within F-Strings” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/format-floats-within-f-strings/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #ff7e74;&quot; alt=&quot;How to Format Floats Within F-Strings in Python&quot; src=&quot;https://files.realpython.com/media/How-to-Display-a-Fixed-Amount-of-Digits-in-a-String_Watermarked.9c8579fa6ac2.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/How-to-Display-a-Fixed-Amount-of-Digits-in-a-String_Watermarked.9c8579fa6ac2.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Display-a-Fixed-Amount-of-Digits-in-a-String_Watermarked.9c8579fa6ac2.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Display-a-Fixed-Amount-of-Digits-in-a-String_Watermarked.9c8579fa6ac2.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Display-a-Fixed-Amount-of-Digits-in-a-String_Watermarked.9c8579fa6ac2.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/format-floats-within-f-strings/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Format Floats Within F-Strings&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of how to format floats within f-strings in Python. This knowledge will let you control the precision and appearance of floating-point numbers when you incorporate them into formatted strings.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;how-to-format-and-round-a-float-within-a-python-f-string&quot;&gt;How to Format and Round a Float Within a Python F-String&lt;a class=&quot;headerlink&quot; href=&quot;#how-to-format-and-round-a-float-within-a-python-f-string&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To format a &lt;code&gt;float&lt;/code&gt; for neat display within a Python f-string, you can use a &lt;strong&gt;format specifier&lt;/strong&gt;. In its most basic form, this allows you to define the &lt;strong&gt;precision&lt;/strong&gt;, or number of decimal places, the &lt;code&gt;float&lt;/code&gt; will be displayed with.&lt;/p&gt;
&lt;p&gt;The code below displays the same calculation as before, only it’s displayed more neatly:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;One third, rounded to two decimal places is: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.2f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;One third, rounded to two decimal places is: 0.33&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To use Python’s format specifiers in a replacement field, you separate them from the expression with a colon (&lt;code&gt;:&lt;/code&gt;). As you can see, your &lt;code&gt;float&lt;/code&gt; has been &lt;a href=&quot;https://realpython.com/python-rounding/&quot;&gt;rounded&lt;/a&gt; to two decimal places. You achieved this by adding the format specifier &lt;code&gt;.2f&lt;/code&gt; into the replacement field. The &lt;code&gt;2&lt;/code&gt; is the precision, while the lowercase &lt;code&gt;f&lt;/code&gt; is an example of a &lt;strong&gt;presentation type&lt;/strong&gt;. You’ll see more of these later.&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 use a format specifier, you don’t actually change the underlying number. You only improve its display.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Python’s f-strings also have their own &lt;a href=&quot;https://docs.python.org/3/library/string.html#format-specification-mini-language&quot;&gt;mini-language&lt;/a&gt; that allows you to format your output in a variety of different ways. Although this tutorial will focus on rounding, this is certainly not the only thing you can use them for. As you’ll see later, their mini-language is also used in other string formatting techniques.&lt;/p&gt;
&lt;p&gt;In addition to displaying the result of calculations, the precision part of a format specifier can also be applied directly to variables and the return values of function calls:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;total_price&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cost&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;cost&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.2&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;cost_price&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&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;tax&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;
&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;£&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;,.2f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; + £&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cost_price&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tax&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;,.2f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; = £&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total_price&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cost_price&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;,.2f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;&#x27;£1,000.00 + £200.00 = £1,200.00&#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This time, you’ve used multiple replacement fields in the same string. The first one formats a literal number, the second formats the result of a calculation, while the third formats the return value from a function call. Also, by inserting a comma (&lt;code&gt;,&lt;/code&gt;) before the decimal point (&lt;code&gt;.&lt;/code&gt;) in the format specifier, you add a thousands separator to your final output.&lt;/p&gt;
&lt;p&gt;In everyday use, you display numbers with a fixed amount of decimals, but when performing scientific or engineering calculations, you may prefer to format them using &lt;a href=&quot;https://en.wikipedia.org/wiki/Significant_figures&quot;&gt;significant figures&lt;/a&gt;. Your results are then assumed to be accurate to the number of significant figures you display them with.&lt;/p&gt;
&lt;p&gt;If you want to round numbers to significant figures, you use the lowercase letter &lt;code&gt;g&lt;/code&gt; in the format specifier. You can also use an uppercase &lt;code&gt;G&lt;/code&gt;, but this automatically switches the format to scientific notation for large numbers.&lt;/p&gt;
&lt;p&gt;Suppose you have a circle with a radius of 10.203 meters. To work out the area, you could use this code:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/how-to-python-f-string-format-float/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/how-to-python-f-string-format-float/ »&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 raise for Effective Exceptions</title>
      <id>https://realpython.com/courses/using-raise-for-effective-exceptions/</id>
      <link href="https://realpython.com/courses/using-raise-for-effective-exceptions/"/>
      <updated>2024-04-16T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to raise exceptions in Python, which will improve your ability to efficiently handle errors and exceptional situations in your code. This way, you&#x27;ll write more reliable, robust, and maintainable code.</summary>
      <content type="html">
        &lt;p&gt;In your Python journey, you&amp;rsquo;ll come across situations where you need to signal that something is going wrong in your code. For example, maybe a file doesn&amp;rsquo;t exist, a network or database connection fails, or your code gets invalid input. A common approach to tackle these issues is to &lt;strong&gt;raise an exception&lt;/strong&gt;, notifying the user that an error has occurred. That&amp;rsquo;s what Python&amp;rsquo;s &lt;code&gt;raise&lt;/code&gt; statement is for.&lt;/p&gt;
&lt;p&gt;Learning about the &lt;code&gt;raise&lt;/code&gt; statement allows you to effectively handle errors and exceptional situations in your code. This way, you&amp;rsquo;ll develop more robust programs and higher-quality code.&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;Raise exceptions in Python using the &lt;strong&gt;&lt;code&gt;raise&lt;/code&gt;&lt;/strong&gt; statement&lt;/li&gt;
&lt;li&gt;Decide &lt;strong&gt;which exceptions&lt;/strong&gt; to raise and &lt;strong&gt;when&lt;/strong&gt; to raise them in your code&lt;/li&gt;
&lt;li&gt;Explore common &lt;strong&gt;use cases&lt;/strong&gt; for raising exceptions in Python&lt;/li&gt;
&lt;li&gt;Apply &lt;strong&gt;best practices&lt;/strong&gt; for raising exceptions in your Python code&lt;/li&gt;
&lt;/ul&gt;
        &lt;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 a Blog Using Django, GraphQL, and Vue</title>
      <id>https://realpython.com/python-django-blog/</id>
      <link href="https://realpython.com/python-django-blog/"/>
      <updated>2024-04-15T14:00:00+00:00</updated>
      <summary>In this step-by-step project, you&#x27;ll build a blog from the ground up. You&#x27;ll turn your Django blog data models into a GraphQL API and consume it in a Vue application for users to read. You&#x27;ll end up with an admin site and a user-facing site you can continue to refine for your own use.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Are you a regular Django user? Do you find yourself wanting to decouple your back end and front end? Do you want to handle data persistence in the API while you display the data in a single-page app (SPA) in the browser using a JavaScript framework like React or Vue? &lt;/p&gt;
&lt;p&gt;If you answered yes to any of these questions, then you’re in luck. This tutorial will take you through the process of building a Django blog back end and a &lt;a href=&quot;https://vuejs.org/&quot;&gt;Vue&lt;/a&gt; front end, using &lt;a href=&quot;https://graphql.org/&quot;&gt;GraphQL&lt;/a&gt; to communicate between them.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://realpython.com/intermediate-python-project-ideas/&quot;&gt;Projects&lt;/a&gt; are an effective way to learn and solidify concepts. This tutorial is structured as a step-by-step project so you can learn in a hands-on way and take breaks as needed.&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;Translate your &lt;strong&gt;Django models&lt;/strong&gt; into a &lt;strong&gt;GraphQL API&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Run the &lt;strong&gt;Django server&lt;/strong&gt; and a &lt;strong&gt;Vue application&lt;/strong&gt; on your computer at the same time&lt;/li&gt;
&lt;li&gt;Administer your blog posts in the &lt;strong&gt;Django admin&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Consume a GraphQL API in Vue to &lt;strong&gt;show data in the browser&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can download all the source code you’ll use to build your Django blog application 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;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/django-vue-graphql/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-django-vue-graphql&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to build a blog using Django, GraphQL, and Vue.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;demo-a-django-blog-admin-a-graphql-api-and-a-vue-front-end&quot;&gt;Demo: A Django Blog Admin, a GraphQL API, and a Vue Front End&lt;a class=&quot;headerlink&quot; href=&quot;#demo-a-django-blog-admin-a-graphql-api-and-a-vue-front-end&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://realpython.com/build-a-blog-from-scratch-django/&quot;&gt;Blog applications&lt;/a&gt; are a common starter project because they involve create, read, update, and delete (CRUD) operations. In this project, you’ll use the Django admin to do the heavy CRUD lifting and you’ll focus on providing a GraphQL API for your blog data.&lt;/p&gt;
&lt;p&gt;You’ll use &lt;a href=&quot;https://vuejs.org/&quot;&gt;Vue.js 3&lt;/a&gt; and its &lt;a href=&quot;https://vuejs.org/glossary/#composition-api&quot;&gt;composition API&lt;/a&gt; for the front end of your blog. Vue lets you create dynamic interfaces pretty smoothly, thanks to its reactive data binding and easy-to-manage components. Plus, since you’re dealing with data from a GraphQL API, you can leverage the Vue Apollo plugin.&lt;/p&gt;
&lt;p&gt;Here’s a demonstration of the completed project in action:&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/918625881?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;Next, you’ll make sure you have all the necessary background information and tools before you dive in and build your blog application.&lt;/p&gt;
&lt;h2 id=&quot;project-overview&quot;&gt;Project Overview&lt;a class=&quot;headerlink&quot; href=&quot;#project-overview&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;For this project, you’ll create a small blogging application with some rudimentary features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Authors&lt;/strong&gt; can write many posts.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Posts&lt;/strong&gt; can have many tags and can be either published or unpublished.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll build the back end of this blog in Django, complete with an admin for adding new blog content. Then you’ll expose the content data as a GraphQL API and use Vue to display that data in the browser.&lt;/p&gt;
&lt;p&gt;You’ll accomplish this in several high-level steps. At the end of each step, you’ll find a link to the source code for that stage of the project.&lt;/p&gt;
&lt;p&gt;If you’re curious about how the source code for each step looks, then you can click the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/django-vue-graphql/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-django-vue-graphql&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to build a blog using Django, GraphQL, and Vue.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;a class=&quot;headerlink&quot; href=&quot;#prerequisites&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You’ll be best equipped for this tutorial if you already have a solid foundation in some web application concepts. You should understand how &lt;a href=&quot;https://realpython.com/python-requests/&quot;&gt;HTTP requests and responses&lt;/a&gt; and APIs work. You can check out &lt;a href=&quot;https://realpython.com/python-api/&quot;&gt;Python &amp;amp; APIs: A Winning Combo for Reading Public Data&lt;/a&gt; to understand the details of using GraphQL APIs vs REST APIs.&lt;/p&gt;
&lt;p&gt;Because you’ll use Django to build the back end for your blog, you’ll want to be familiar with &lt;a href=&quot;https://realpython.com/django-setup/&quot;&gt;starting a Django project&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/customize-django-admin-python/&quot;&gt;customizing the Django admin&lt;/a&gt;. If you haven’t used Django much before, you might also want to try building another Django-only project first. For a good introduction, check out &lt;a href=&quot;https://realpython.com/get-started-with-django-1/&quot;&gt;Get Started with Django Part 1: Build a Portfolio App&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And because you’ll be using Vue on the front end, some experience with &lt;a href=&quot;https://realpython.com/python-vs-javascript/&quot;&gt;JavaScript&lt;/a&gt; will also help. If you’ve only used a JavaScript framework like &lt;a href=&quot;https://jquery.com/&quot;&gt;jQuery&lt;/a&gt; in the past, the &lt;a href=&quot;https://vuejs.org/guide/introduction.html&quot;&gt;Vue introduction&lt;/a&gt; is a good foundation.&lt;/p&gt;
&lt;p&gt;Familiarity with JSON is also important because GraphQL queries are JSON-like and return data in JSON format. You can read about &lt;a href=&quot;https://realpython.com/python-json/&quot;&gt;Working with JSON Data in Python&lt;/a&gt; for an introduction.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-django-blog/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-django-blog/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Write Pythonic and Clean Code With namedtuple</title>
      <id>https://realpython.com/quizzes/python-namedtuple/</id>
      <link href="https://realpython.com/quizzes/python-namedtuple/"/>
      <updated>2024-04-15T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s namedtuple() function from the collections module. This function allows you to create immutable sequence types that you can access using descriptive field names and dot notation.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/python-namedtuple/&quot;&gt;Python&amp;rsquo;s &lt;code&gt;namedtuple()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to create &lt;code&gt;namedtuple&lt;/code&gt; classes, identify and take advantage of the cool features of &lt;code&gt;namedtuple&lt;/code&gt;, use &lt;code&gt;namedtuple&lt;/code&gt; instances to write Pythonic code, and decide when to use a &lt;code&gt;namedtuple&lt;/code&gt; over a similar data structure.&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 #200: Avoiding Error Culture and Getting Help Inside Python</title>
      <id>https://realpython.com/podcasts/rpp/200/</id>
      <link href="https://realpython.com/podcasts/rpp/200/"/>
      <updated>2024-04-12T12:00:00+00:00</updated>
      <summary>What is error culture, and how do you avoid it within your organization? How do you navigate alert and notification fatigue? Hey, it&#x27;s episode #200! Real Python&#x27;s editor-in-chief, Dan Bader, joins us this week to celebrate. Christopher Trudeau also returns to bring another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What is error culture, and how do you avoid it within your organization? How do you navigate alert and notification fatigue? Hey, it&#x27;s episode #200! Real Python&#x27;s editor-in-chief, Dan Bader, joins us this week to celebrate. Christopher Trudeau also returns to bring another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: What&#x27;s Lazy Evaluation in Python?</title>
      <id>https://realpython.com/quizzes/python-lazy-evaluation/</id>
      <link href="https://realpython.com/quizzes/python-lazy-evaluation/"/>
      <updated>2024-04-12T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of the differences between lazy and eager evaluation in Python. By working through this quiz, you&#x27;ll revisit how Python optimizes memory use and computational overhead by deciding when to compute values.</summary>
      <content type="html">
        &lt;p&gt;Lazy evaluation is a programming concept where the evaluation of an expression is deferred until its value is actually needed. This can lead to performance enhancements by avoiding unnecessary calculations, and it can also allow for the creation of potentially infinite data structures. As you embark on this quiz, you&amp;rsquo;ll test your knowledge of lazy evaluation in Python and learn how to apply this concept to write cleaner and more efficient code.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Format Floats Within F-Strings</title>
      <id>https://realpython.com/quizzes/format-floats-within-f-strings/</id>
      <link href="https://realpython.com/quizzes/format-floats-within-f-strings/"/>
      <updated>2024-04-12T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of how to format floats within f-strings in Python. This knowledge will let you control the precision and appearance of floating-point numbers when you incorporate them into formatted strings.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/how-to-python-f-string-format-float/&quot;&gt;How to Format Floats Within F-Strings in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll often need to format and round a Python &lt;code&gt;float&lt;/code&gt; to display the results of your calculations neatly within strings. While there are several ways to format numbers in Python, formatted string literals or &lt;a href=&quot;https://realpython.com/python-f-strings/&quot;&gt;f-strings&lt;/a&gt; are usually the most frequent choice in modern Python programs. Knowing how to use f-strings effectively can make your code more readable and concise.&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>Pydantic: Simplifying Data Validation in Python</title>
      <id>https://realpython.com/python-pydantic/</id>
      <link href="https://realpython.com/python-pydantic/"/>
      <updated>2024-04-10T14:00:00+00:00</updated>
      <summary>Discover the power of Pydantic, Python&#x27;s most popular data parsing, validation, and serialization library. In this hands-on tutorial, you&#x27;ll learn how to make your code more robust, trustworthy, and easier to debug with Pydantic.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Pydantic is a powerful data validation and settings management library for Python, engineered to enhance the robustness and reliability of your codebase. From basic tasks, such as checking whether a variable is an integer, to more complex tasks, like ensuring highly-nested dictionary keys and values have the correct data types, Pydantic can handle just about any data validation scenario with minimal boilerplate code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Work with &lt;strong&gt;data schemas&lt;/strong&gt; with Pydantic’s &lt;code&gt;BaseModel&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Write &lt;strong&gt;custom validators&lt;/strong&gt; for complex use cases&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validate function arguments&lt;/strong&gt; with Pydantic’s &lt;code&gt;@validate_call&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Manage settings and &lt;strong&gt;configure applications&lt;/strong&gt; with &lt;code&gt;pydantic-settings&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Throughout this tutorial, you’ll get hands-on examples of Pydantic’s functionalities, and by the end you’ll have a solid foundation for your own validation use cases. Before starting this tutorial, you’ll benefit from having an intermediate understanding of Python and &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt;. &lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/pydantic-simplifying-data-validation-in-python/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-pydantic-simplifying-data-validation-in-python&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to help you learn how Pydantic can help you simplify data validation in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;pythons-pydantic-library&quot;&gt;Python’s Pydantic Library&lt;a class=&quot;headerlink&quot; href=&quot;#pythons-pydantic-library&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;One of Python’s main attractions is that it’s a dynamically typed language. Dynamic typing means that variable types are determined at runtime, unlike statically typed languages where they are explicitly declared at compile time. While dynamic typing is great for rapid development and ease of use, you often need more robust type checking and data validation for real-world applications. This is where Python’s Pydantic library has you covered.&lt;/p&gt;
&lt;p&gt;Pydantic has quickly gained popularity, and it’s now the most widely used data validation library for Python. In this first section, you’ll get an overview of Pydantic and a preview of the library’s powerful features. You’ll also learn how to install Pydantic along with the additional dependencies you’ll need for this tutorial.&lt;/p&gt;
&lt;h3 id=&quot;getting-familiar-with-pydantic&quot;&gt;Getting Familiar With Pydantic&lt;a class=&quot;headerlink&quot; href=&quot;#getting-familiar-with-pydantic&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Pydantic is a powerful Python library that leverages &lt;a href=&quot;https://realpython.com/python-type-checking/&quot;&gt;type hints&lt;/a&gt; to help you easily validate and serialize your data schemas. This makes your code more robust, readable, concise, and easier to debug. Pydantic also integrates well with many popular static typing tools and IDEs, which allows you to catch schema issues before running your code.&lt;/p&gt;
&lt;p&gt;Some of Pydantic’s distinguishing features include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Customization&lt;/strong&gt;: There’s almost no limit to the kinds of data you can validate with Pydantic. From primitive Python types to highly nested data structures, Pydantic lets you validate and serialize nearly any Python object.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flexibility&lt;/strong&gt;: Pydantic gives you control over how strict or lax you want to be when validating your data. In some cases, you might want to coerce incoming data to the correct type. For example, you could accept data that’s intended to be a float but is received as an integer. In other cases, you might want to strictly enforce the data types you’re receiving. Pydantic enables you to do either. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Serialization&lt;/strong&gt;: You can serialize and deserialize Pydantic objects as &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionaries&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-json/&quot;&gt;JSON&lt;/a&gt; strings. This means that you can seamlessly convert your Pydantic objects to and from JSON. This capability has led to self-documenting APIs and integration with just about any tool that supports JSON schemas.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Thanks to its core validation logic written in &lt;a href=&quot;https://www.rust-lang.org/&quot;&gt;Rust&lt;/a&gt;, Pydantic is exceptionally fast. This performance advantage gives you swift and reliable data processing, especially in high-throughput applications such as REST APIs that need to scale to a large number of requests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Ecosystem and Industry Adoption&lt;/strong&gt;: Pydantic is a dependency of &lt;a href=&quot;https://docs.pydantic.dev/2.0/why/#ecosystem&quot;&gt;many popular Python libraries&lt;/a&gt; such as &lt;a href=&quot;https://realpython.com/fastapi-python-web-apis/&quot;&gt;FastAPI&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/build-llm-rag-chatbot-with-langchain/&quot;&gt;LangChain&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/polars-python/&quot;&gt;Polars&lt;/a&gt;. It’s also used by most of the &lt;a href=&quot;https://docs.pydantic.dev/2.0/why/#using-pydantic&quot;&gt;largest tech companies&lt;/a&gt; and throughout many other industries. This is a testament to Pydantic’s community support, reliability, and resilience.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are a few key features that make Pydantic an attractive data validation library, and you’ll get to see these in action throughout this tutorial. Up next, you’ll get an overview of how to install Pydantic along with its various dependencies.&lt;/p&gt;
&lt;h3 id=&quot;installing-pydantic&quot;&gt;Installing Pydantic&lt;a class=&quot;headerlink&quot; href=&quot;#installing-pydantic&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Pydantic is available on &lt;a href=&quot;https://pypi.org/&quot;&gt;PyPI&lt;/a&gt;, and you can install it with &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;pip&lt;/a&gt;. Open a terminal or command prompt, create a new virtual environment, and then run the following command to install Pydantic:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp gp-VirtualEnv&quot;&gt;(venv)&lt;/span&gt; &lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pydantic
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This command will install the latest version of Pydantic from PyPI onto your machine. To verify that the installation was successful, start a &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python REPL&lt;/a&gt; and import Pydantic:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pydantic&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If the import runs without error, then you’ve successfully installed Pydantic, and you now have the core of Pydantic installed on your system.&lt;/p&gt;
&lt;h3 id=&quot;adding-optional-dependencies&quot;&gt;Adding Optional Dependencies&lt;a class=&quot;headerlink&quot; href=&quot;#adding-optional-dependencies&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;You can install optional dependencies with Pydantic as well. For example, you’ll be working with email validation in this tutorial, and you can include these dependencies in your install:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp gp-VirtualEnv&quot;&gt;(venv)&lt;/span&gt; &lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;pydantic[email]&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Pydantic has a separate package for &lt;a href=&quot;https://docs.pydantic.dev/latest/concepts/pydantic_settings/&quot;&gt;settings management&lt;/a&gt;, which you’ll also cover in this tutorial. To install this, run the following command:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp gp-VirtualEnv&quot;&gt;(venv)&lt;/span&gt; &lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pydantic-settings
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With that, you’ve installed all the dependencies you’ll need for this tutorial, and you’re ready to start exploring Pydantic. You’ll start by covering models—Pydantic’s primary way of defining data schemas.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-pydantic/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-pydantic/ »&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>Generating QR Codes With Python</title>
      <id>https://realpython.com/courses/generating-qr-codes/</id>
      <link href="https://realpython.com/courses/generating-qr-codes/"/>
      <updated>2024-04-09T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to use Python to generate QR codes, from your standard black-and-white QR codes to beautiful ones with your favorite colors. You&#x27;ll learn how to format QR codes, rotate them, and even replace the static background with moving images.</summary>
      <content type="html">
        &lt;p&gt;From restaurant e-menus to airline boarding passes, &lt;strong&gt;QR codes&lt;/strong&gt; have numerous applications that impact your day-to-day life and enrich the user&amp;rsquo;s experience. Wouldn&amp;rsquo;t it be great to make them look good, too? With the help of this video course, you&amp;rsquo;ll learn how to use Python to generate beautiful QR codes for your personal use case. &lt;/p&gt;
&lt;p&gt;In its most basic format, a QR code contains black squares and dots on a white background, with information that any smartphone or device with a dedicated QR scanner can decode. Unlike a traditional bar code, which holds information horizontally, a QR code holds the data in two dimensions, and it can hold over a hundred times more information.&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;Generate&lt;/strong&gt; a basic black-and-white QR code&lt;/li&gt;
&lt;li&gt;Change the &lt;strong&gt;size&lt;/strong&gt; and &lt;strong&gt;margins&lt;/strong&gt; of the QR code&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;colorful&lt;/strong&gt; QR codes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rotate&lt;/strong&gt; the QR code&lt;/li&gt;
&lt;li&gt;Replace the static background with an &lt;strong&gt;animated GIF&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python News: What&#x27;s New From March 2024</title>
      <id>https://realpython.com/python-news-march-2024/</id>
      <link href="https://realpython.com/python-news-march-2024/"/>
      <updated>2024-04-08T14:00:00+00:00</updated>
      <summary>In March 2024, the first release candidate of NumPy was published. At the same time, the PSF announced a new position that will improve the PyPI user support, and the free-threaded Python project reached an exciting milestone.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;While many people went hunting for &lt;a href=&quot;https://realpython.com/courses/finding-python-easter-eggs/&quot;&gt;Easter eggs&lt;/a&gt;, the Python community stayed active through March 2024. The free-threaded Python project reached a new milestone, and you can now experiment with disabling the GIL in your interpreter.&lt;/p&gt;
&lt;p&gt;The Python Software Foundation does a great job supporting the language with limited resources. They’ve now announced a new position that will support users of PyPI. NumPy is an old workhorse in the data science space. The library is getting a big facelift, and the first release candidate of NumPy 2 is now available.&lt;/p&gt;
&lt;p&gt;Dive in to learn more about last month’s most important Python news. &lt;/p&gt;
&lt;h2 id=&quot;free-threaded-python-reaches-an-important-milestone&quot;&gt;Free-Threaded Python Reaches an Important Milestone&lt;a class=&quot;headerlink&quot; href=&quot;#free-threaded-python-reaches-an-important-milestone&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python’s &lt;a href=&quot;https://realpython.com/python-gil/&quot;&gt;global interpreter lock&lt;/a&gt; (GIL) has been part of the CPython implementation since the early days. The lock simplifies a lot of the code under the hood of the language, but also causes some issues with &lt;a href=&quot;https://realpython.com/python-parallel-processing/&quot;&gt;parallel processing&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Over the years, there have been &lt;a href=&quot;https://realpython.com/python-parallel-processing/#the-gil-ensures-thread-safety-of-the-python-internals&quot;&gt;many attempts&lt;/a&gt; to remove the GIL. However, until &lt;a href=&quot;https://peps.python.org/pep-0703/&quot;&gt;PEP 703&lt;/a&gt; was &lt;a href=&quot;https://realpython.com/python-news-october-2023/#pep-703-accepted-one-step-closer-to-python-without-the-gil&quot;&gt;accepted by the steering council last year&lt;/a&gt;, none had been successful.&lt;/p&gt;
&lt;p&gt;The PEP describes how the GIL can be removed based on experimental work done by &lt;a href=&quot;https://github.com/colesbury&quot;&gt;Sam Gross&lt;/a&gt;. It suggests that what’s now called &lt;strong&gt;free-threaded Python&lt;/strong&gt; is activated through a build option. In time, this free-threaded Python is expected to become the default version of CPython, but for now, it’s only meant for testing and experiments.&lt;/p&gt;
&lt;p&gt;When free-threaded Python is ready for bigger audiences, the GIL will still be enabled by default. You can then set an environment variable or add a command-line option to try out free-threaded Python:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-march-2024/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-march-2024/ »&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 #199: Leveraging Documents and Data to Create a Custom LLM Chatbot</title>
      <id>https://realpython.com/podcasts/rpp/199/</id>
      <link href="https://realpython.com/podcasts/rpp/199/"/>
      <updated>2024-04-05T12:00:00+00:00</updated>
      <summary>How do you customize a LLM chatbot to address a collection of documents and data? What tools and techniques can you use to build embeddings into a vector database? This week on the show, Calvin Hendryx-Parker is back to discuss developing an AI-powered, Large Language Model-driven chat interface.</summary>
      <content type="html">
        &lt;p&gt;How do you customize a LLM chatbot to address a collection of documents and data? What tools and techniques can you use to build embeddings into a vector database? This week on the show, Calvin Hendryx-Parker is back to discuss developing an AI-powered, Large Language Model-driven chat interface.&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>Install and Execute Python Applications Using pipx</title>
      <id>https://realpython.com/python-pipx/</id>
      <link href="https://realpython.com/python-pipx/"/>
      <updated>2024-04-03T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about a tool called pipx, which lets you conveniently install and run Python packages as standalone command-line applications in isolated environments. In a way, pipx turns the Python Package Index (PyPI) into an app marketplace for Python programmers.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;A straightforward way to distribute &lt;strong&gt;desktop&lt;/strong&gt; and &lt;strong&gt;command-line applications&lt;/strong&gt; written in Python is to &lt;a href=&quot;https://realpython.com/pypi-publish-python-package/&quot;&gt;publish them&lt;/a&gt; on the &lt;a href=&quot;https://pypi.org/&quot;&gt;Python Package Index (PyPI)&lt;/a&gt;, which hosts hundreds of thousands of &lt;a href=&quot;https://realpython.com/python-package-quality/&quot;&gt;third-party packages&lt;/a&gt;. Many of these packages include &lt;a href=&quot;https://realpython.com/run-python-scripts/&quot;&gt;runnable scripts&lt;/a&gt;, but using them requires decent familiarity with the Python ecosystem. With &lt;code&gt;pipx&lt;/code&gt;, you can safely install and execute such applications without affecting your global Python interpreter.&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;Turn the &lt;strong&gt;Python Package Index (PyPI)&lt;/strong&gt; into an &lt;strong&gt;app marketplace&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Run installed applications &lt;strong&gt;without explicitly calling Python&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Avoid &lt;strong&gt;dependency conflicts&lt;/strong&gt; between different applications&lt;/li&gt;
&lt;li&gt;Try &lt;strong&gt;throw-away applications&lt;/strong&gt; in temporary locations&lt;/li&gt;
&lt;li&gt;Manage the &lt;strong&gt;installed applications&lt;/strong&gt; and their &lt;strong&gt;environments&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To fully benefit from this tutorial, you should feel comfortable around the &lt;a href=&quot;https://realpython.com/terminal-commands/&quot;&gt;terminal&lt;/a&gt;. In particular, knowing how to &lt;a href=&quot;https://realpython.com/intro-to-pyenv/&quot;&gt;manage Python versions&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-virtual-environments-a-primer/&quot;&gt;create virtual environments&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;install third-party modules&lt;/a&gt; in your projects will go a long 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; If you’re a Windows user, then it’s highly recommended you follow our &lt;a href=&quot;https://realpython.com/python-coding-setup-windows/&quot;&gt;Python coding setup guide&lt;/a&gt; before plunging into this tutorial. The gist of it is that you should avoid installing Python from the &lt;a href=&quot;https://en.wikipedia.org/wiki/Microsoft_Store&quot;&gt;Microsoft Store&lt;/a&gt;, as it could prevent &lt;code&gt;pipx&lt;/code&gt; from working correctly.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;To help you get to grips with &lt;code&gt;pipx&lt;/code&gt;, you can download the supplemental materials, which include a handy command cheat sheet. Additionally, you can test your understanding by taking a short quiz.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Cheatsheet:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-pipx-cheatsheet/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-pipx-cheatsheet&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free cheatsheet&lt;/a&gt; of pipx commands you can use to install and execute Python applications.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Install and Execute Python Applications Using pipx” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-pipx/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #ff7e74;&quot; alt=&quot;Install and Execute Python Applications Using pipx&quot; src=&quot;https://files.realpython.com/media/Pipx_Watermarked-2.f0dce855ba80.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Pipx_Watermarked-2.f0dce855ba80.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Pipx_Watermarked-2.f0dce855ba80.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Pipx_Watermarked-2.f0dce855ba80.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Pipx_Watermarked-2.f0dce855ba80.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-pipx/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Install and Execute Python Applications Using pipx&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of how Python apps are run from isolated virtual environments using the pipx tool. With this knowledge, you&#x27;ll be able to safely run Python apps that are installed globally in your operating system.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;get-started-with-pipx&quot;&gt;Get Started With &lt;code&gt;pipx&lt;/code&gt;&lt;a class=&quot;headerlink&quot; href=&quot;#get-started-with-pipx&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;On the surface, &lt;a href=&quot;https://pipx.pypa.io/stable/&quot;&gt;&lt;code&gt;pipx&lt;/code&gt;&lt;/a&gt; resembles &lt;code&gt;pip&lt;/code&gt; because it also lets you install Python packages from PyPI or another &lt;a href=&quot;https://packaging.python.org/en/latest/glossary/#term-Package-Index&quot;&gt;package index&lt;/a&gt;. However, unlike &lt;code&gt;pip&lt;/code&gt;, it doesn’t install packages into your system-wide Python interpreter or even an activated virtual environment. Instead, it automatically creates and manages virtual environments for you to isolate the dependencies of every package that you install.&lt;/p&gt;
&lt;p&gt;Additionally, &lt;code&gt;pipx&lt;/code&gt; adds &lt;a href=&quot;https://en.wikipedia.org/wiki/Symbolic_link&quot;&gt;symbolic links&lt;/a&gt; to your &lt;a href=&quot;https://en.wikipedia.org/wiki/PATH_(variable)&quot;&gt;&lt;code&gt;PATH&lt;/code&gt;&lt;/a&gt; variable for every command-line script exposed by the installed packages. As a result, you can invoke those scripts directly from the command line without explicitly running them through the Python interpreter.&lt;/p&gt;
&lt;p&gt;Think of &lt;code&gt;pipx&lt;/code&gt; as Python’s equivalent of &lt;a href=&quot;https://docs.npmjs.com/cli/v10/commands/npx&quot;&gt;&lt;code&gt;npx&lt;/code&gt;&lt;/a&gt; in the &lt;a href=&quot;https://realpython.com/python-vs-javascript/&quot;&gt;JavaScript&lt;/a&gt; ecosystem. Both tools let you install and execute third-party &lt;a href=&quot;https://realpython.com/python-modules-packages/&quot;&gt;modules&lt;/a&gt; in the command line just as if they were &lt;strong&gt;standalone applications&lt;/strong&gt;. However, not all modules are created equal.&lt;/p&gt;
&lt;p&gt;Broadly speaking, you can classify the code distributed through PyPI into three categories:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Importable:&lt;/strong&gt; It’s either pure-Python source code or &lt;a href=&quot;https://realpython.com/python-bindings-overview/&quot;&gt;Python bindings&lt;/a&gt; of compiled shared objects that you want to &lt;a href=&quot;https://realpython.com/python-import/&quot;&gt;import&lt;/a&gt; in your Python projects. Typically, they’re libraries like &lt;a href=&quot;https://realpython.com/python-requests/&quot;&gt;Requests&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/polars-python/&quot;&gt;Polars&lt;/a&gt;, providing reusable pieces of code to help you solve a common problem. Alternatively, they might be frameworks like &lt;a href=&quot;https://realpython.com/fastapi-python-web-apis/&quot;&gt;FastAPI&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/pygame-a-primer/&quot;&gt;PyGame&lt;/a&gt; that you build your applications around.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Runnable:&lt;/strong&gt; These are usually command-line utility tools like &lt;a href=&quot;https://pypi.org/project/black/&quot;&gt;&lt;code&gt;black&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://pypi.org/project/isort/&quot;&gt;&lt;code&gt;isort&lt;/code&gt;&lt;/a&gt;, or &lt;a href=&quot;https://pypi.org/project/flake8/&quot;&gt;&lt;code&gt;flake8&lt;/code&gt;&lt;/a&gt; that assist you during the development phase. They could also be full-fledged applications like &lt;a href=&quot;https://realpython.com/bpython-alternative-python-repl/&quot;&gt;&lt;code&gt;bpython&lt;/code&gt;&lt;/a&gt; or the &lt;a href=&quot;https://realpython.com/using-jupyterlab/&quot;&gt;JupyterLab&lt;/a&gt; environment, which is primarily implemented in a foreign &lt;a href=&quot;https://www.typescriptlang.org/&quot;&gt;TypeScript&lt;/a&gt; programming language.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid:&lt;/strong&gt; They combine both worlds by providing importable code and runnable scripts at the same time. &lt;a href=&quot;https://realpython.com/learning-paths/flask-by-example/&quot;&gt;Flask&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/learning-paths/django-web-development/&quot;&gt;Django&lt;/a&gt; are good examples, as they offer utility scripts while remaining web frameworks for the most part.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Making a &lt;a href=&quot;https://packaging.python.org/en/latest/glossary/#term-Distribution-Package&quot;&gt;distribution package&lt;/a&gt; runnable or hybrid involves defining one or more &lt;a href=&quot;https://en.wikipedia.org/wiki/Entry_point&quot;&gt;entry points&lt;/a&gt; in the corresponding configuration file. Historically, these would be &lt;code&gt;setup.py&lt;/code&gt; or &lt;code&gt;setup.cfg&lt;/code&gt;, but modern build systems in Python should generally rely on the &lt;a href=&quot;https://packaging.python.org/en/latest/guides/writing-pyproject-toml/&quot;&gt;&lt;code&gt;pyproject.toml&lt;/code&gt;&lt;/a&gt; file and define their entry points in the &lt;code&gt;[project.scripts]&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-toml/#tables&quot;&gt;TOML table&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you use &lt;a href=&quot;https://realpython.com/dependency-management-python-poetry/&quot;&gt;Poetry&lt;/a&gt; to manage your project’s dependencies, then you can add the appropriate &lt;a href=&quot;https://python-poetry.org/docs/pyproject/#scripts&quot;&gt;script declarations&lt;/a&gt; in the tool-specific &lt;code&gt;[tool.poetry.scripts]&lt;/code&gt; table.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Each entry point represents an independent script that you can run by typing its name at the command prompt. For example, if you’ve ever used the &lt;a href=&quot;https://docs.djangoproject.com/en/5.0/ref/django-admin/&quot;&gt;&lt;code&gt;django-admin&lt;/code&gt;&lt;/a&gt; command, then you’ve called out an entry point to the Django framework.&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; Don’t confuse &lt;a href=&quot;https://packaging.python.org/en/latest/specifications/entry-points/&quot;&gt;entry points&lt;/a&gt;, which link to individual &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/python-callable-instances/&quot;&gt;callables&lt;/a&gt; in your code, with runnable Python packages that rely on the &lt;a href=&quot;https://docs.python.org/3/library/__main__.html#main-py-in-python-packages&quot;&gt;&lt;code&gt;__main__&lt;/code&gt;&lt;/a&gt; module to provide a command-line interface.&lt;/p&gt;
&lt;p&gt;For example, &lt;a href=&quot;https://realpython.com/python-rich-package/&quot;&gt;Rich&lt;/a&gt; is a library of building blocks for creating text-based user interfaces in Python. At the same time, you can run this package with &lt;code&gt;python -m rich&lt;/code&gt; to display a demo application that illustrates various visual components at your fingertips. Despite this, &lt;code&gt;pipx&lt;/code&gt; won’t recognize it as runnable because the library doesn’t define any entry points.&lt;/p&gt;
&lt;p&gt;To sum up, the &lt;code&gt;pipx&lt;/code&gt; tool will only let you install Python packages with at least one entry point. It’ll refuse to install runnable packages like Rich and bare-bones libraries that ship Python code meant just for importing.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Once you identify a Python package with entry points that you’d like to use, you should first create and activate a dedicated &lt;strong&gt;virtual environment&lt;/strong&gt; as a best practice. By keeping the package isolated from the rest of your system, you’ll eliminate the risk of &lt;a href=&quot;https://en.wikipedia.org/wiki/Dependency_hell&quot;&gt;dependency conflicts&lt;/a&gt; across various projects that might require the same Python library in different versions. Furthermore, you won’t need the &lt;a href=&quot;https://en.wikipedia.org/wiki/Superuser&quot;&gt;superuser&lt;/a&gt; permissions to install the package.&lt;/p&gt;
&lt;p&gt;Deciding where and how to create a virtual environment and then remembering to activate it every time before running the corresponding script can become a burden. Fortunately, &lt;code&gt;pipx&lt;/code&gt; automates these steps and provides even more features that you’ll explore in this tutorial. But first, you need to get &lt;code&gt;pipx&lt;/code&gt; running itself.&lt;/p&gt;
&lt;h3 id=&quot;test-drive-pipx-without-installation&quot;&gt;Test Drive &lt;code&gt;pipx&lt;/code&gt; Without Installation&lt;a class=&quot;headerlink&quot; href=&quot;#test-drive-pipx-without-installation&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you’re unsure whether &lt;code&gt;pipx&lt;/code&gt; will address your needs and would prefer not to commit to it until you’ve properly tested the tool, then there’s good news! Thanks to a &lt;strong&gt;self-contained executable&lt;/strong&gt; available for download, you can give &lt;code&gt;pipx&lt;/code&gt; a spin without having to install it.&lt;/p&gt;
&lt;p&gt;To get that executable, visit the project’s &lt;a href=&quot;https://github.com/pypa/pipx/releases&quot;&gt;release page&lt;/a&gt; on the official &lt;a href=&quot;https://realpython.com/python-git-github-intro/&quot;&gt;GitHub&lt;/a&gt; repository in your web browser and grab the latest version of a file named &lt;code&gt;pipx.pyz&lt;/code&gt;. Files with the &lt;code&gt;.pyz&lt;/code&gt; extension represent runnable &lt;a href=&quot;https://realpython.com/python-zipapp/&quot;&gt;Python ZIP applications&lt;/a&gt;, which are essentially ZIP archives containing Python source code and some metadata, akin to &lt;a href=&quot;https://en.wikipedia.org/wiki/JAR_(file_format)&quot;&gt;JAR&lt;/a&gt; files in &lt;a href=&quot;https://realpython.com/java-vs-python/&quot;&gt;Java&lt;/a&gt;. They can optionally vendor third-party dependencies that you’d otherwise have to install by hand.&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; Internally, the &lt;code&gt;pipx&lt;/code&gt; project uses &lt;a href=&quot;https://pypi.org/project/shiv/&quot;&gt;&lt;code&gt;shiv&lt;/code&gt;&lt;/a&gt; to build its Python ZIP application. When you first run a Python ZIP application that was built with &lt;code&gt;shiv&lt;/code&gt;, it’ll unpack itself into a hidden folder named &lt;code&gt;.shiv/&lt;/code&gt; located in your user’s &lt;a href=&quot;https://en.wikipedia.org/wiki/Home_directory&quot;&gt;home directory&lt;/a&gt;. As a result, subsequent runs of the same application will reuse the already extracted files, speeding up the startup time.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Afterward, you can run &lt;code&gt;pipx.pyz&lt;/code&gt; by passing the path to your downloaded copy of the file to your Python interpreter—just as you would with a regular Python script:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-pipx/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-pipx/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Build Command-Line Interfaces With Python&#x27;s argparse</title>
      <id>https://realpython.com/quizzes/command-line-interfaces-python-argparse/</id>
      <link href="https://realpython.com/quizzes/command-line-interfaces-python-argparse/"/>
      <updated>2024-04-03T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of creating command-line interfaces (CLIs) in Python using the argparse module. This knowledge is essential for creating user-friendly command-line apps, which are common in development, data science, and systems administration.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/command-line-interfaces-python-argparse/&quot;&gt;Creating Command-line Interfaces in Python with argparse&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Command-line apps may not be common in the general user&amp;rsquo;s space, but they&amp;rsquo;re present in development, data science, systems administration, and many other operations. Every command-line app needs a user-friendly &lt;a href=&quot;https://en.wikipedia.org/wiki/Command-line_interface&quot;&gt;command-line interface (CLI)&lt;/a&gt; so that you can interact with the app itself. In Python, you can create full-featured CLIs with the &lt;code&gt;argparse&lt;/code&gt; module from the standard library.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Deep Learning: PyTorch vs Tensorflow</title>
      <id>https://realpython.com/courses/deep-learning-pytorch-tensorflow/</id>
      <link href="https://realpython.com/courses/deep-learning-pytorch-tensorflow/"/>
      <updated>2024-04-02T14:00:00+00:00</updated>
      <summary>PyTorch vs Tensorflow: Which one should you use? Learn about these two popular deep learning libraries and how to choose the best one for your project.</summary>
      <content type="html">
        &lt;p&gt;PyTorch vs TensorFlow: What&amp;rsquo;s the difference? Both are open source Python libraries that use graphs to perform numerical computation on data. Both are used extensively in academic research and commercial code. Both are extended by a variety of APIs, cloud computing platforms, and model repositories.&lt;/p&gt;
&lt;p&gt;If they&amp;rsquo;re so similar, then which one is best for your project?&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 the differences are between &lt;strong&gt;PyTorch&lt;/strong&gt; and &lt;strong&gt;TensorFlow&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;tools&lt;/strong&gt; and &lt;strong&gt;resources&lt;/strong&gt; are available for each&lt;/li&gt;
&lt;li&gt;How to choose the &lt;strong&gt;best option&lt;/strong&gt; for your specific use case&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You&amp;rsquo;ll start by taking a close look at both platforms, beginning with the slightly older TensorFlow, before exploring some considerations that can help you determine which choice is best for your project. Let&amp;rsquo;s get started!&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 #198: Build a Video Game With Python Turtle &amp; Visualize Data in Seaborn</title>
      <id>https://realpython.com/podcasts/rpp/198/</id>
      <link href="https://realpython.com/podcasts/rpp/198/"/>
      <updated>2024-03-29T12:00:00+00:00</updated>
      <summary>Can you build a Space Invaders clone using Python&#x27;s built-in turtle module? What advantages does the Seaborn data visualization library provide compared to Matplotlib? Christopher Trudeau is back on the show this week, along with special guest Real Python core team member Bartosz Zaczyński. We&#x27;re sharing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;Can you build a Space Invaders clone using Python&#x27;s built-in turtle module? What advantages does the Seaborn data visualization library provide compared to Matplotlib? Christopher Trudeau is back on the show this week, along with special guest Real Python core team member Bartosz Zaczyński. We&#x27;re sharing 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>Reading and Writing WAV Files in Python</title>
      <id>https://realpython.com/python-wav-files/</id>
      <link href="https://realpython.com/python-wav-files/"/>
      <updated>2024-03-27T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to work with WAV audio files in Python using the standard-library wave module. Along the way, you&#x27;ll synthesize sounds from scratch, visualize waveforms in the time domain, animate real-time spectrograms, and apply special effects to widen the stereo field.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;There’s an abundance of third-party tools and libraries for manipulating and analyzing audio WAV files in Python. At the same time, the language ships with the little-known &lt;code&gt;wave&lt;/code&gt; module in its standard library, offering a quick and straightforward way to read and write such files. Knowing Python’s &lt;code&gt;wave&lt;/code&gt; module can help you dip your toes into digital audio processing.&lt;/p&gt;
&lt;p&gt;If topics like audio analysis, sound editing, or music synthesis get you excited, then you’re in for a treat, as you’re about to get a taste of them!&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; and &lt;strong&gt;write&lt;/strong&gt; WAV files using pure Python&lt;/li&gt;
&lt;li&gt;Handle the 24-bit &lt;strong&gt;PCM encoding&lt;/strong&gt; of audio samples&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interpret&lt;/strong&gt; and &lt;strong&gt;plot&lt;/strong&gt; the underlying &lt;strong&gt;amplitude levels&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Record &lt;strong&gt;online audio streams&lt;/strong&gt; like Internet radio stations&lt;/li&gt;
&lt;li&gt;Animate &lt;strong&gt;visualizations&lt;/strong&gt; in the &lt;strong&gt;time&lt;/strong&gt; and &lt;strong&gt;frequency&lt;/strong&gt; domains&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Synthesize&lt;/strong&gt; sounds and apply &lt;strong&gt;special effects&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Although not required, you’ll get the most out of this tutorial if you’re familiar with &lt;a href=&quot;https://realpython.com/numpy-tutorial/&quot;&gt;NumPy&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-matplotlib-guide/&quot;&gt;Matplotlib&lt;/a&gt;, which greatly simplify working with audio data. Additionally, knowing about &lt;a href=&quot;https://realpython.com/python-array/&quot;&gt;numeric arrays&lt;/a&gt; in Python will help you better understand the underlying data representation in computer memory.&lt;/p&gt;
&lt;p&gt;Click the link below to access the bonus materials, where you’ll find &lt;strong&gt;sample audio files&lt;/strong&gt; for practice, as well as the &lt;strong&gt;complete source code&lt;/strong&gt; of all the examples demonstrated in 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;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-wav-files-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-wav-files-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to read and write WAV files in Python.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You can also take the quiz to test your knowledge and see how much you’ve learned:&lt;/p&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Reading and Writing WAV Files in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/python-wav-files/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe5b2;&quot; alt=&quot;Reading and Writing WAV Files in Python&quot; src=&quot;https://files.realpython.com/media/Read-and-Write-WAV-Files-with-Python-Wave_Watermarked.da2e8047b2da.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Read-and-Write-WAV-Files-with-Python-Wave_Watermarked.da2e8047b2da.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Read-and-Write-WAV-Files-with-Python-Wave_Watermarked.da2e8047b2da.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Read-and-Write-WAV-Files-with-Python-Wave_Watermarked.da2e8047b2da.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Read-and-Write-WAV-Files-with-Python-Wave_Watermarked.da2e8047b2da.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/python-wav-files/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Reading and Writing WAV Files in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you can test your knowledge of handling WAV audio files in Python with the wave module. By applying what you&#x27;ve learned, you&#x27;ll demonstrate your ability to synthesize sounds, analyze and visualize waveforms, create dynamic spectrograms, and enhance audio with special effects.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;understand-the-wav-file-format&quot;&gt;Understand the WAV File Format&lt;a class=&quot;headerlink&quot; href=&quot;#understand-the-wav-file-format&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In the early nineties, Microsoft and IBM jointly developed the &lt;a href=&quot;https://en.wikipedia.org/wiki/WAV&quot;&gt;Waveform Audio File Format&lt;/a&gt;, often abbreviated as WAVE or WAV, which stems from the file’s extension (&lt;code&gt;.wav&lt;/code&gt;). Despite its older age in computer terms, the format remains relevant today. There are several good reasons for its wide adoption, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Simplicity:&lt;/strong&gt; The WAV file format has a straightforward structure, making it relatively uncomplicated to decode in software and understand by humans.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Portability:&lt;/strong&gt; Many software systems and hardware platforms support the WAV file format as standard, making it suitable for data exchange.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High Fidelity:&lt;/strong&gt; Because most WAV files contain raw, uncompressed audio data, they’re perfect for applications that require the highest possible sound quality, such as with music production or audio editing. On the flipside, WAV files take up significant storage space compared to &lt;a href=&quot;https://en.wikipedia.org/wiki/Lossy_compression&quot;&gt;lossy compression&lt;/a&gt; formats like MP3.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It’s worth noting that WAV files are specialized kinds of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Resource_Interchange_File_Format&quot;&gt;Resource Interchange File Format (RIFF)&lt;/a&gt;, which is a container format for audio and video streams. Other popular file formats based on RIFF include &lt;a href=&quot;https://en.wikipedia.org/wiki/Audio_Video_Interleave&quot;&gt;AVI&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/MIDI&quot;&gt;MIDI&lt;/a&gt;. RIFF itself is an extension of an even older &lt;a href=&quot;https://en.wikipedia.org/wiki/Interchange_File_Format&quot;&gt;IFF&lt;/a&gt; format originally developed by Electronic Arts to store video game resources.&lt;/p&gt;
&lt;p&gt;Before diving in, you’ll deconstruct the WAV file format itself to better understand its structure and how it represents sounds. Feel free to jump ahead if you just want to see &lt;a href=&quot;#get-to-know-pythons-wave-module&quot;&gt;how to use the &lt;code&gt;wave&lt;/code&gt; module&lt;/a&gt; in Python.&lt;/p&gt;
&lt;h3 id=&quot;the-waveform-part-of-wav&quot;&gt;The Waveform Part of WAV&lt;a class=&quot;headerlink&quot; href=&quot;#the-waveform-part-of-wav&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;What you perceive as sound is a disturbance of pressure traveling through a physical medium, such as air or water. At the most fundamental level, every sound is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Wave&quot;&gt;wave&lt;/a&gt; that you can describe using three attributes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Amplitude&quot;&gt;Amplitude&lt;/a&gt; is the measure of the sound wave’s strength, which you perceive as &lt;a href=&quot;https://en.wikipedia.org/wiki/Loudness&quot;&gt;loudness&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Frequency&quot;&gt;Frequency&lt;/a&gt; is the reciprocal of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Wavelength&quot;&gt;wavelength&lt;/a&gt; or the number of oscillations per second, which corresponds to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Pitch_(music)&quot;&gt;pitch&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Phase_(waves)&quot;&gt;Phase&lt;/a&gt; is the point in the wave cycle at which the wave starts, not registered by the human ear directly.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The word &lt;a href=&quot;https://en.wikipedia.org/wiki/Waveform&quot;&gt;waveform&lt;/a&gt;, which appears in the WAV file format’s name, refers to the graphical depiction of the audio signal’s shape. If you’ve ever opened a sound file using audio editing software, such as &lt;a href=&quot;https://www.audacityteam.org/&quot;&gt;Audacity&lt;/a&gt;, then you’ve likely seen a visualization of the file’s content that looked something like this:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/audacity_waveform.d53954eea4a1.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/audacity_waveform.d53954eea4a1.png&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/audacity_waveform.d53954eea4a1.png 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/audacity_waveform.d53954eea4a1.png 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/audacity_waveform.d53954eea4a1.png 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/audacity_waveform.d53954eea4a1.png 1920w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;Waveform in Audacity&quot; data-asset=&quot;5691&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Waveform in Audacity&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;That’s your audio waveform, illustrating how the amplitude changes over time.&lt;/p&gt;
&lt;p&gt;The vertical axis represents the &lt;strong&gt;amplitude&lt;/strong&gt; at any given point in time. The midpoint of the graph, which is a horizontal line passing through the center, represents the baseline amplitude or the point of silence. Any deviation from this equilibrium corresponds to a higher positive or negative amplitude, which you experience as a louder sound.&lt;/p&gt;
&lt;p&gt;As you move from left to right along the graph’s horizontal scale, which is the &lt;strong&gt;timeline&lt;/strong&gt;, you’re essentially moving forward in time through your audio track.&lt;/p&gt;
&lt;p&gt;Having such a view can help you visually inspect the characteristics of your audio file. The series of the amplitude’s peaks and valleys reflect the volume changes. Therefore, you can leverage the waveform to identify parts where certain sounds occur or find quiet sections that may need editing.&lt;/p&gt;
&lt;p&gt;Coming up next, you’ll learn how WAV files store these amplitude levels in digital form.&lt;/p&gt;
&lt;h3 id=&quot;the-structure-of-a-wav-file&quot;&gt;The Structure of a WAV File&lt;a class=&quot;headerlink&quot; href=&quot;#the-structure-of-a-wav-file&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-wav-files/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-wav-files/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: A Practical Introduction to Web Scraping in Python</title>
      <id>https://realpython.com/quizzes/python-web-scraping-practical-introduction/</id>
      <link href="https://realpython.com/quizzes/python-web-scraping-practical-introduction/"/>
      <updated>2024-03-27T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of web scraping in Python. Web scraping is a powerful tool for data collection and analysis. By working through this quiz, you&#x27;ll revisit how to parse website data using string methods, regular expressions, and HTML parsers, as well as how to interact with forms and other website components.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/python-web-scraping-practical-introduction/&quot;&gt;Web Scraping in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to parse website data using string methods and regular expressions, how to parse website data using an HTML parser, and how to interact with forms and other website components.&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>Finding Python Easter Eggs</title>
      <id>https://realpython.com/courses/finding-python-easter-eggs/</id>
      <link href="https://realpython.com/courses/finding-python-easter-eggs/"/>
      <updated>2024-03-26T14:00:00+00:00</updated>
      <summary>Python has its fair share of hidden surprises, commonly known as Easter eggs. From clever jokes to secret messages, these little mysteries are often meant to be discovered by curious geeks like you!</summary>
      <content type="html">
        &lt;p&gt;In this &lt;strong&gt;Code Conversation&lt;/strong&gt;, you&amp;rsquo;ll follow a chat between Philipp and Bartosz as they go on an Easter egg hunt. Along the way, you&amp;rsquo;ll:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Learn about Easter egg hunt traditions&lt;/li&gt;
&lt;li&gt;Uncover the first Easter egg in software&lt;/li&gt;
&lt;li&gt;Explore Easter eggs in Python&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There won&amp;rsquo;t be many code examples in this Code Conversation, so you can lean back and join Philipp and Bartosz on their Easter egg hunt.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Get Started With Django: Build a Portfolio App</title>
      <id>https://realpython.com/quizzes/get-started-with-django/</id>
      <link href="https://realpython.com/quizzes/get-started-with-django/"/>
      <updated>2024-03-26T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Django, a fully featured Python web framework. By working through this quiz, you&#x27;ll revisit the steps to create a fully functioning web application and learn about some of Django&#x27;s most important features.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of &lt;a href=&quot;https://realpython.com/learning-paths/django-web-development/&quot;&gt;Django&lt;/a&gt;. By working through this quiz, you&amp;rsquo;ll revisit the steps you need to &lt;a href=&quot;https://realpython.com/get-started-with-django-1/&quot;&gt;get started with Django&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll touch on topics that will help you create a fully functioning web application and revisit some of the most important features of Django.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll also investigate the architecture of a Django site, remember how to set up a new Django project with multiple apps, build models and views, and create and connect Django templates.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Inheritance and Composition: A Python OOP Guide</title>
      <id>https://realpython.com/quizzes/inheritance-composition-python/</id>
      <link href="https://realpython.com/quizzes/inheritance-composition-python/"/>
      <updated>2024-03-26T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of inheritance and composition in Python. These are two major concepts in object-oriented programming that help model the relationship between two classes. By working through this quiz, you&#x27;ll revisit how to use inheritance and composition in Python, model class hierarchies, and use multiple inheritance.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;Inheritance and Composition in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to use inheritance and composition in Python, model class hierarchies, and use multiple inheritance.&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>Prompt Engineering: A Practical Example</title>
      <id>https://realpython.com/practical-prompt-engineering/</id>
      <link href="https://realpython.com/practical-prompt-engineering/"/>
      <updated>2024-03-25T14:00:00+00:00</updated>
      <summary>Learn prompt engineering techniques with a practical, real-world project to get better results from large language models. This tutorial covers zero-shot and few-shot prompting, delimiters, numbered steps, role prompts, chain-of-thought prompting, and more. Improve your LLM-assisted projects today.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;You’ve used &lt;a href=&quot;https://realpython.com/chatgpt-coding-mentor-python/&quot;&gt;ChatGPT&lt;/a&gt;, and you understand the potential of using a &lt;strong&gt;large language model (LLM)&lt;/strong&gt; to assist you in your tasks. Maybe you’re already working on an LLM-supported application and have read about &lt;strong&gt;prompt engineering&lt;/strong&gt;, but you’re unsure how to translate the theoretical concepts into a practical example.&lt;/p&gt;
&lt;p&gt;Your text prompt instructs the LLM’s responses, so tweaking it can get you vastly different output. In this tutorial, you’ll apply multiple &lt;strong&gt;prompt engineering techniques&lt;/strong&gt; to a real-world example. You’ll experience prompt engineering as an iterative process, see the effects of applying various techniques, and learn about related concepts from machine learning and data engineering.&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;Work with OpenAI’s &lt;strong&gt;GPT-3.5&lt;/strong&gt; and &lt;strong&gt;GPT-4&lt;/strong&gt; models through their &lt;strong&gt;API&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Apply prompt engineering techniques to a &lt;strong&gt;practical, real-world example&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;numbered steps&lt;/strong&gt;, &lt;strong&gt;delimiters&lt;/strong&gt;, and &lt;strong&gt;few-shot prompting&lt;/strong&gt; to improve your results&lt;/li&gt;
&lt;li&gt;Understand and use &lt;strong&gt;chain-of-thought prompting&lt;/strong&gt; to add more context&lt;/li&gt;
&lt;li&gt;Tap into the power of &lt;strong&gt;roles&lt;/strong&gt; in messages to go beyond using singular &lt;strong&gt;role prompts&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll work with a &lt;strong&gt;Python script&lt;/strong&gt; that you can repurpose to fit your own LLM-assisted task. So if you’d like to use practical examples to discover how you can use prompt engineering to get better results from an LLM, then you’ve found the right 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;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/prompt-engineering-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-prompt-engineering-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the sample code &lt;/a&gt; that you’ll use to get the most out of large language models through prompt engineering.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

  &lt;p class=&quot;my-3&quot;&gt;&lt;mark class=&quot;marker-highlight&quot;&gt;&lt;strong&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “Practical Prompt Engineering” quiz. You’ll receive a score upon completion to help you track your learning progress:&lt;/p&gt;

  &lt;hr&gt;

  &lt;div class=&quot;row my-3&quot;&gt;
    &lt;div class=&quot;col-xs-12 col-sm-4 col-md-3 align-self-center&quot;&gt;

      &lt;a href=&quot;/quizzes/practical-prompt-engineering/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #ffc873;&quot; alt=&quot;Prompt Engineering: A Practical Example&quot; src=&quot;https://files.realpython.com/media/Prompt-Engineering-A-Practical-Example_Watermarked.7106fe3647aa.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Prompt-Engineering-A-Practical-Example_Watermarked.7106fe3647aa.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Prompt-Engineering-A-Practical-Example_Watermarked.7106fe3647aa.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Prompt-Engineering-A-Practical-Example_Watermarked.7106fe3647aa.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Prompt-Engineering-A-Practical-Example_Watermarked.7106fe3647aa.jpg 1920w&quot; sizes=&quot;(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)&quot;&gt;


          &lt;div class=&quot;card-img-overlay d-flex align-items-center&quot;&gt;
            &lt;div class=&quot;mx-auto&quot;&gt;
              &lt;span class=&quot;text-light&quot; style=&quot;opacity: 0.90;&quot;&gt;&lt;span class=&quot;icon baseline scale2x&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/a&gt;

    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;div class=&quot;mt-3 d-md-none&quot;&gt;&lt;/div&gt; 
      &lt;p class=&quot;small text-muted mb-0&quot;&gt;&lt;strong&gt;Interactive Quiz&lt;/strong&gt;&lt;/p&gt;
      &lt;a href=&quot;/quizzes/practical-prompt-engineering/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Practical Prompt Engineering&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of prompt engineering techniques with large language models (LLMs) like GPT-3.5 and GPT-4. You&#x27;ll revisit how to work with OpenAI&#x27;s API, apply prompt engineering techniques to practical examples, and use various strategies to improve your results.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;understand-the-purpose-of-prompt-engineering&quot;&gt;Understand the Purpose of Prompt Engineering&lt;a class=&quot;headerlink&quot; href=&quot;#understand-the-purpose-of-prompt-engineering&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Prompt engineering is more than a buzzword. You can get vastly different output from an LLM when using different prompts. That may seem obvious when you consider that you get different output when you ask different questions—but it also applies to phrasing the same conceptual question differently. Prompt engineering means constructing your text input to the LLM using specific approaches.&lt;/p&gt;
&lt;p&gt;You can think of prompts as arguments and the LLM as the function to which you pass these arguments. Different input means different output:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hello&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;go&quot;&gt;Hello, World!&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;hello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Engineer&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Hello, Engineer!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;While an LLM is much more complex than the toy function above, the fundamental idea holds true. For a successful function call, you’ll need to know exactly which argument will produce the desired output. In the case of an LLM, that argument is text that consists of many different &lt;strong&gt;tokens&lt;/strong&gt;, or &lt;a href=&quot;https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them&quot;&gt;pieces of words&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The analogy of a function and its arguments has a caveat when dealing with OpenAI’s LLMs. While the &lt;code&gt;hello()&lt;/code&gt; function above will always return the same result given the same input, the results of your LLM interactions won’t be 100 percent deterministic. This is currently inherent to how these models operate.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The field of prompt engineering is still changing rapidly, and there’s a lot of active research happening in this area. As LLMs continue to evolve, so will the prompting approaches that will help you achieve the best results.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll cover some prompt engineering techniques, along with approaches to iteratively developing prompts, that you can use to get better text completions for your own LLM-assisted projects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#describe-your-task&quot;&gt;Zero-Shot Prompting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#use-few-shot-prompting-to-improve-output&quot;&gt;Few-Shot Prompting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#use-delimiters-to-clearly-mark-sections-of-your-prompt&quot;&gt;Delimiters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#describe-your-request-in-numbered-steps&quot;&gt;Numbered Steps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#add-a-role-prompt-to-set-the-tone&quot;&gt;Role Prompts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#walk-the-model-through-chain-of-thought-prompting&quot;&gt;Chain-of-Thought (CoT) Prompting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#structure-your-output-format-as-json&quot;&gt;Structured Output&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#improve-your-output-with-the-power-of-conversation&quot;&gt;Labeled Conversations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are more techniques to uncover, and you’ll also find links to additional resources in the tutorial. Applying the mentioned techniques in a practical example will give you a great starting point for improving your LLM-supported programs. If you’ve never worked with an LLM before, then you may want to peruse &lt;a href=&quot;https://platform.openai.com/docs/guides/gpt&quot;&gt;OpenAI’s GPT documentation&lt;/a&gt; before diving in, but you should be able to follow along either way.&lt;/p&gt;
&lt;h2 id=&quot;get-to-know-the-practical-prompt-engineering-project&quot;&gt;Get to Know the Practical Prompt Engineering Project&lt;a class=&quot;headerlink&quot; href=&quot;#get-to-know-the-practical-prompt-engineering-project&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You’ll explore various prompt engineering techniques in service of a practical example: &lt;a href=&quot;https://en.wikipedia.org/wiki/Data_sanitization&quot;&gt;sanitizing&lt;/a&gt; customer chat conversations. By practicing different prompt engineering techniques on a single real-world project, you’ll get a good idea of why you might want to use one technique over another and how you can apply them in practice.&lt;/p&gt;
&lt;p&gt;Imagine that you’re the resident Python developer at a company that handles thousands of customer support chats on a daily basis. Your job is to format and sanitize these conversations. You also help with deciding which of them require additional attention.&lt;/p&gt;
&lt;h3 id=&quot;collect-your-tasks&quot;&gt;Collect Your Tasks&lt;a class=&quot;headerlink&quot; href=&quot;#collect-your-tasks&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Your big-picture assignment is to help your company stay on top of handling customer chat conversations. The conversations that you work with may look like the one shown below:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;text&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--grey&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Text&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;[support_tom] 2023-07-24T10:02:23+00:00 : What can I help you with?
[johndoe] 2023-07-24T10:03:15+00:00 : I CAN&#x27;T CONNECT TO MY BLASTED ACCOUNT
[support_tom] 2023-07-24T10:03:30+00:00 : Are you sure it&#x27;s not your caps lock?
[johndoe] 2023-07-24T10:04:03+00:00 : Blast! You&#x27;re right!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/button&gt;
    &lt;template class=&quot;codeblock__copied-template&quot;&gt;
      &lt;span class=&quot;small&quot;&gt;&lt;span class=&quot;icon baseline mr-1 text-success&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.f06b05d28f37.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You’re supposed to make these text conversations more accessible for further processing by the customer support department in a few different ways:&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Remove personally identifiable information.&lt;/li&gt;
&lt;li&gt;Remove swear words.&lt;/li&gt;
&lt;li&gt;Clean the date-time information to only show the date.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/practical-prompt-engineering/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/practical-prompt-engineering/ »&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 #197: Using Python in Bioinformatics and the Laboratory</title>
      <id>https://realpython.com/podcasts/rpp/197/</id>
      <link href="https://realpython.com/podcasts/rpp/197/"/>
      <updated>2024-03-22T12:00:00+00:00</updated>
      <summary>How is Python being used to automate processes in the laboratory? How can it speed up scientific work with DNA sequencing? This week on the show, Chemical Engineering PhD Student Parsa Ghadermazi is here to discuss Python in bioinformatics.</summary>
      <content type="html">
        &lt;p&gt;How is Python being used to automate processes in the laboratory? How can it speed up scientific work with DNA sequencing? This week on the show, Chemical Engineering PhD Student Parsa Ghadermazi is here to discuss Python in bioinformatics.&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>SQLite and SQLAlchemy in Python: Move Your Data Beyond Flat Files</title>
      <id>https://realpython.com/courses/sqlite-sqlalchemy-python-beyond-flat-files/</id>
      <link href="https://realpython.com/courses/sqlite-sqlalchemy-python-beyond-flat-files/"/>
      <updated>2024-03-19T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to store and retrieve data using Python, SQLite, and SQLAlchemy as well as with flat files. Using SQLite with Python brings with it the additional benefit of accessing data with SQL. By adding SQLAlchemy, you can work with data in terms of objects and methods.</summary>
      <content type="html">
        &lt;p&gt;All programs process data in one form or another, and many need to be able to save and retrieve that data from one invocation to the next. Python, &lt;a href=&quot;https://www.sqlite.org/index.html&quot;&gt;SQLite&lt;/a&gt;, and &lt;a href=&quot;https://www.sqlalchemy.org/&quot;&gt;SQLAlchemy&lt;/a&gt; give your programs database functionality, allowing you to store data in a single file without the need for a database server.&lt;/p&gt;
&lt;p&gt;You can achieve similar results using &lt;a href=&quot;https://en.wikipedia.org/wiki/Flat-file_database&quot;&gt;flat files&lt;/a&gt; in any number of formats, including CSV, JSON, XML, and even custom formats. Flat files are often human-readable text files&amp;mdash;though they can also be binary data&amp;mdash;with a structure that can be parsed by a computer program. You&amp;rsquo;ll explore using SQL databases and flat files for data storage and manipulation and learn how to decide which approach is right for your program.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to use:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Flat files&lt;/strong&gt; for data storage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL&lt;/strong&gt; to improve access to persistent data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQLite&lt;/strong&gt; for data storage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQLAlchemy&lt;/strong&gt; to work with data as Python objects&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #196: Exploring Duck Typing in Python &amp; Dynamics of Monkey Patching</title>
      <id>https://realpython.com/podcasts/rpp/196/</id>
      <link href="https://realpython.com/podcasts/rpp/196/"/>
      <updated>2024-03-15T12:00:00+00:00</updated>
      <summary>What are the advantages of determining the type of an object by how it behaves? What coding circumstances are not a good fit for duck typing? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the advantages of determining the type of an object by how it behaves? What coding circumstances are not a good fit for duck typing? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Basics Exercises: Dictionaries</title>
      <id>https://realpython.com/courses/basics-exercises-dictionaries/</id>
      <link href="https://realpython.com/courses/basics-exercises-dictionaries/"/>
      <updated>2024-03-12T14:00:00+00:00</updated>
      <summary>One of the most useful data structures in Python is the dictionary. In this video course, you’ll practice working with Python dictionaries, see how dictionaries differ from lists and tuples, and define and use dictionaries in your own code.</summary>
      <content type="html">
        &lt;p&gt;In plain English, a dictionary is a book containing the definitions of words. Each entry in a dictionary has two parts: the word being defined, and its definition.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Python dictionaries&lt;/strong&gt;, like lists and tuples, store a collection of objects. However, instead of storing objects in a sequence, dictionaries hold
information in pairs of data called &lt;strong&gt;key-value pairs&lt;/strong&gt;. That is, each object in a dictionary has two parts: a &lt;strong&gt;key&lt;/strong&gt; and a &lt;strong&gt;value&lt;/strong&gt;. Each key is assigned a single value, which defines the relationship between the two sets.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What a dictionary &lt;strong&gt;is&lt;/strong&gt; and how it&amp;rsquo;s &lt;strong&gt;structured&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How dictionaries &lt;strong&gt;differ&lt;/strong&gt; from other data structures&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;define&lt;/strong&gt; and &lt;strong&gt;use&lt;/strong&gt; dictionaries in your own code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This video course is part of the Python Basics series, which accompanies &lt;a href=&quot;https://realpython.com/products/python-basics-book/&quot;&gt;&lt;em&gt;Python Basics: A Practical Introduction to Python 3&lt;/em&gt;&lt;/a&gt;. You can also check out the other &lt;a href=&quot;https://realpython.com/learning-paths/python-basics/&quot;&gt;Python Basics courses&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Note that you&amp;rsquo;ll be using &lt;a href=&quot;https://realpython.com/python-idle/&quot;&gt;IDLE&lt;/a&gt; to &lt;a href=&quot;https://realpython.com/interacting-with-python/&quot;&gt;interact with Python&lt;/a&gt; throughout this course.&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 #195: Building a Healthy Developer Mindset While Learning Python</title>
      <id>https://realpython.com/podcasts/rpp/195/</id>
      <link href="https://realpython.com/podcasts/rpp/195/"/>
      <updated>2024-03-08T12:00:00+00:00</updated>
      <summary>How do you get yourself unstuck when facing a programming problem? How do you develop a positive developer mindset while learning Python? This week on the show, Bob Belderbos from Pybites is here to talk about learning Python and building healthy developer habits.</summary>
      <content type="html">
        &lt;p&gt;How do you get yourself unstuck when facing a programming problem? How do you develop a positive developer mindset while learning Python? This week on the show, Bob Belderbos from Pybites is here to talk about learning Python and building healthy developer habits.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Creating Asynchronous Tasks With Celery and Django</title>
      <id>https://realpython.com/courses/asynchronous-tasks-celery-django/</id>
      <link href="https://realpython.com/courses/asynchronous-tasks-celery-django/"/>
      <updated>2024-03-05T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to integrate Celery and Django using Redis as a message broker. You&#x27;ll refactor the synchronous email sending functionality of an existing Django app into an asynchronous task that you&#x27;ll run with Celery instead.</summary>
      <content type="html">
        &lt;p&gt;You&amp;rsquo;ve built a shiny &lt;strong&gt;Django&lt;/strong&gt; app and want to release it to the public, but you&amp;rsquo;re worried about time-intensive tasks that are part of your app&amp;rsquo;s workflow. You don&amp;rsquo;t want your users to have a negative experience navigating your app. You can integrate &lt;strong&gt;Celery&lt;/strong&gt; to help with that.&lt;/p&gt;
&lt;p&gt;Celery is a &lt;strong&gt;distributed task queue&lt;/strong&gt; for UNIX systems. It allows you to offload work from your Python app. Once you integrate Celery into your app, you can send time-intensive tasks to Celery&amp;rsquo;s task queue. That way, your web app can continue to respond quickly to users while Celery completes expensive operations asynchronously in the background.&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;Recognize &lt;strong&gt;effective use cases&lt;/strong&gt; for Celery&lt;/li&gt;
&lt;li&gt;Differentiate between &lt;strong&gt;Celery beat&lt;/strong&gt; and &lt;strong&gt;Celery workers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integrate Celery and Redis&lt;/strong&gt; in a Django project&lt;/li&gt;
&lt;li&gt;Set up &lt;strong&gt;asynchronous tasks&lt;/strong&gt; that run independently of your Django app&lt;/li&gt;
&lt;li&gt;Refactor Django code to &lt;strong&gt;run a task with Celery&lt;/strong&gt; instead&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #194: Automate Tasks With Python &amp; Building a Small Search Engine</title>
      <id>https://realpython.com/podcasts/rpp/194/</id>
      <link href="https://realpython.com/podcasts/rpp/194/"/>
      <updated>2024-03-01T12:00:00+00:00</updated>
      <summary>What are the typical computer tasks you do manually every week? Could you automate those tasks with a Python script? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the typical computer tasks you do manually every week? Could you automate those tasks with a Python script? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Basics Exercises: Installing Packages With pip</title>
      <id>https://realpython.com/courses/basics-exercises-install-packages-with-pip/</id>
      <link href="https://realpython.com/courses/basics-exercises-install-packages-with-pip/"/>
      <updated>2024-02-27T14:00:00+00:00</updated>
      <summary>In this Python Basics Exercises video course, you&#x27;ll practice installing packages with pip. You&#x27;ll also practice creating virtual environments, making lists of requirements, and recreating a development environment.</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;In this Python Basics Exercises course, you&amp;rsquo;ll test and reinforce your knowledge of installing packages and managing virtual environments.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Installing&lt;/strong&gt; and &lt;strong&gt;managing&lt;/strong&gt; third-party packages with &lt;code&gt;pip&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;virtual environments&lt;/strong&gt; to separate project dependencies&lt;/li&gt;
&lt;li&gt;Declaring &lt;strong&gt;requirements&lt;/strong&gt; and &lt;strong&gt;re-create&lt;/strong&gt; a development environment&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By the end of this course, you&amp;rsquo;ll have an even stronger grasp of installing 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 #193: Wes McKinney on Improving the Data Stack &amp; Composable Systems</title>
      <id>https://realpython.com/podcasts/rpp/193/</id>
      <link href="https://realpython.com/podcasts/rpp/193/"/>
      <updated>2024-02-23T12:00:00+00:00</updated>
      <summary>How do you avoid the bottlenecks of data processing systems? Is it possible to build tools that decouple storage and computation? This week on the show, creator of the pandas library Wes McKinney is here to discuss Apache Arrow, composable data systems, and community collaboration.</summary>
      <content type="html">
        &lt;p&gt;How do you avoid the bottlenecks of data processing systems? Is it possible to build tools that decouple storage and computation? This week on the show, creator of the pandas library Wes McKinney is here to discuss Apache Arrow, composable data systems, and community collaboration.&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>
