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

  
    <entry>
      <title>Python Classes: The Power of Object-Oriented Programming</title>
      <id>https://realpython.com/python-classes/</id>
      <link href="https://realpython.com/python-classes/"/>
      <updated>2024-08-19T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to create and use full-featured classes in your Python code. Classes provide a great way to solve complex programming problems by approaching them through models that represent real-world objects.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python supports the &lt;strong&gt;object-oriented&lt;/strong&gt; programming paradigm through &lt;strong&gt;classes&lt;/strong&gt;. They provide an elegant way to define reusable pieces of code that encapsulate data and behavior in a single entity. With classes, you can quickly and intuitively model real-world objects and solve complex problems.&lt;/p&gt;
&lt;p&gt;If you’re new to classes, need to refresh your knowledge, or want to dive deeper into them, then this tutorial is for you!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Define Python classes with the &lt;strong&gt;&lt;code&gt;class&lt;/code&gt; keyword&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Add state to your classes with &lt;strong&gt;class&lt;/strong&gt; and &lt;strong&gt;instance attributes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Provide &lt;strong&gt;behavior&lt;/strong&gt; to your classes with &lt;strong&gt;methods&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;inheritance&lt;/strong&gt; to build hierarchies of classes&lt;/li&gt;
&lt;li&gt;Provide &lt;strong&gt;interfaces&lt;/strong&gt; with &lt;strong&gt;abstract classes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should know about Python &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-data-types/&quot;&gt;data types&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;. Some experience with &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming (OOP)&lt;/a&gt; is also a plus. Don’t worry if you’re not an OOP expert yet. In this tutorial, you’ll learn the key concepts that you need to get started and more. You’ll also write several practical examples to help reinforce your knowledge of Python classes.&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-classes-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-classes-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download your free sample code&lt;/a&gt; that shows you how to build powerful object blueprints with classes 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.1440a154cfa8.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 Classes - The Power of Object-Oriented Programming” 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-classes-oop/&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 Classes: The Power of Object-Oriented Programming&quot; src=&quot;https://files.realpython.com/media/Class-Concepts-Object-Oriented-Programming-in-Python_Watermarked.6cf327c51434.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Class-Concepts-Object-Oriented-Programming-in-Python_Watermarked.6cf327c51434.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Class-Concepts-Object-Oriented-Programming-in-Python_Watermarked.6cf327c51434.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Class-Concepts-Object-Oriented-Programming-in-Python_Watermarked.6cf327c51434.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Class-Concepts-Object-Oriented-Programming-in-Python_Watermarked.6cf327c51434.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.1440a154cfa8.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-classes-oop/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python Classes - The Power of Object-Oriented Programming&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 classes. With this knowledge, you&#x27;ll be able to define reusable pieces of code that encapsulate data and behavior in a single entity, model real-world objects, and solve complex problems.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-started-with-python-classes&quot;&gt;Getting Started With Python Classes&lt;a class=&quot;headerlink&quot; href=&quot;#getting-started-with-python-classes&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Programming_paradigm&quot;&gt;multiparadigm&lt;/a&gt; programming language that supports &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming (OOP)&lt;/a&gt; through classes that you can define with the &lt;code&gt;class&lt;/code&gt; keyword. You can think of a class as a piece of code that specifies the &lt;strong&gt;data&lt;/strong&gt; and &lt;strong&gt;behavior&lt;/strong&gt; that represent and model a particular type of object.&lt;/p&gt;
&lt;p&gt;What is a class in Python? A common analogy is that a class is like the blueprint for a house. You can use the blueprint to create several houses and even a complete neighborhood. Each concrete house is an &lt;strong&gt;object&lt;/strong&gt; or &lt;strong&gt;instance&lt;/strong&gt; that’s derived from the blueprint.&lt;/p&gt;
&lt;p&gt;Each instance can have its own properties, such as color, owner, and interior design. These properties carry what’s commonly known as the object’s &lt;a href=&quot;https://en.wikipedia.org/wiki/State_(computer_science)&quot;&gt;state&lt;/a&gt;. Instances can also have different behaviors, such as locking the doors and windows, opening the garage door, turning the lights on and off, watering the garden, and more.&lt;/p&gt;
&lt;p&gt;In OOP, you commonly use the term &lt;strong&gt;attributes&lt;/strong&gt; to refer to the properties or data associated with a specific object of a given class. In Python, attributes are &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt; defined inside a class with the purpose of storing all the required data for the class to work.&lt;/p&gt;
&lt;p&gt;Similarly, you’ll use the term &lt;strong&gt;methods&lt;/strong&gt; to refer to the different behaviors that objects will show. Methods are functions that you define within a class. These functions typically operate on or with the attributes of the underlying instance or class. Attributes and methods are collectively referred to as &lt;strong&gt;members&lt;/strong&gt; of a class or object.&lt;/p&gt;
&lt;p&gt;You can write classes to model the real world. These classes will help you better organize your code and solve complex programming problems.&lt;/p&gt;
&lt;p&gt;For example, you can use classes to create objects that emulate people, animals, vehicles, books, buildings, cars, or other objects. You can also model virtual objects, such as a web server, &lt;a href=&quot;https://realpython.com/directory-tree-generator-python/#coding-the-high-level-directorytree-class&quot;&gt;directory tree&lt;/a&gt;, chatbot, file manager, and more.&lt;/p&gt;
&lt;p&gt;Finally, you can use classes to build &lt;strong&gt;class hierarchies&lt;/strong&gt;. This way, you’ll promote code reuse and remove repetition throughout your codebase.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll learn a lot about classes and all the cool things that you can do with them. To kick things off, you’ll start by defining your first class in Python. Then you’ll dive into other topics related to instances, attributes, and methods.&lt;/p&gt;
&lt;h3 id=&quot;defining-a-class-in-python&quot;&gt;Defining a Class in Python&lt;a class=&quot;headerlink&quot; href=&quot;#defining-a-class-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To define a class, you need to use the &lt;code&gt;class&lt;/code&gt; keyword followed by the class name and a colon, just like you’d do for other &lt;a href=&quot;https://docs.python.org/3/reference/compound_stmts.html&quot;&gt;compound statements&lt;/a&gt; in Python. Then you must define the class body, which will start at the next indentation level:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python_syntax&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python Syntax&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ClassName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In a class’s body, you can define attributes and methods as needed. As you already learned, attributes are variables that hold the class data, while methods are functions that provide behavior and typically act on the class data.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In Python, the body of a given class works as a &lt;a href=&quot;https://realpython.com/python-namespaces-scope/&quot;&gt;namespace&lt;/a&gt; where attributes and methods live. You can only access those attributes and methods through the class or its objects.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As an example of how to define attributes and methods, say that you need a &lt;code&gt;Circle&lt;/code&gt; class to model different circles in a drawing application. Initially, your class will have a single attribute to hold the radius. It’ll also have a method to calculate the circle’s area:&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;circle.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;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;math&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;radius&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;radius&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;calculate_area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;math&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;radius&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this code snippet, you define &lt;code&gt;Circle&lt;/code&gt; using the &lt;code&gt;class&lt;/code&gt; keyword. Inside the class, you write two methods. The &lt;code&gt;.__init__()&lt;/code&gt; method has a special meaning in Python classes. This method is known as the object &lt;a href=&quot;https://realpython.com/python-class-constructor/#object-initialization-with-__init__&quot;&gt;initializer&lt;/a&gt; because it defines and sets the initial values for the object’s attributes. You’ll learn more about this method in the &lt;a href=&quot;#instance-attributes&quot;&gt;Instance Attributes&lt;/a&gt; section.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-classes/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-classes/ »&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 #217: Packaging Data Analyses &amp; Using pandas GroupBy</title>
      <id>https://realpython.com/podcasts/rpp/217/</id>
      <link href="https://realpython.com/podcasts/rpp/217/"/>
      <updated>2024-08-16T12:00:00+00:00</updated>
      <summary>What are the best practices for organizing data analysis projects in Python? What are the advantages of a more package-centric approach to data science? 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 best practices for organizing data analysis projects in Python? What are the advantages of a more package-centric approach to data science? 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: Web Scraping With Scrapy and MongoDB</title>
      <id>https://realpython.com/quizzes/web-scraping-with-scrapy-and-mongodb/</id>
      <link href="https://realpython.com/quizzes/web-scraping-with-scrapy-and-mongodb/"/>
      <updated>2024-08-16T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of web scraping with Scrapy and MongoDB. You&#x27;ll revisit how to set up a Scrapy project, build a functional web scraper, extract data from websites, store scraped data in MongoDB, and test and debug your Scrapy web scraper.</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/web-scraping-with-scrapy-and-mongodb/&quot;&gt;Web Scraping with Scrapy and MongoDB&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to set up a Scrapy project, build a functional web scraper, extract data from websites using selectors, store scraped data in a MongoDB database, and test and debug your Scrapy web scraper.&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 Walrus Operator: Python&#x27;s Assignment Expressions</title>
      <id>https://realpython.com/python-walrus-operator/</id>
      <link href="https://realpython.com/python-walrus-operator/"/>
      <updated>2024-08-14T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about assignment expressions and the walrus operator. The biggest change back in Python 3.8 was the inclusion of the := operator, which you can use to assign variables in the middle of expressions. You&#x27;ll see several examples of how to take advantage of this feature.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Each new version of Python adds new features to the language. Back when Python 3.8 was released, the biggest change was the addition of &lt;strong&gt;assignment expressions&lt;/strong&gt;. Specifically, the &lt;code&gt;:=&lt;/code&gt; operator gave you a new syntax for assigning variables in the middle of expressions. This operator is colloquially known as the &lt;strong&gt;walrus operator&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This tutorial is an in-depth introduction to the walrus operator. You’ll learn some of the motivations for the syntax update and explore examples where assignment expressions can be useful.&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;Identify &lt;strong&gt;the walrus operator&lt;/strong&gt; and understand its meaning&lt;/li&gt;
&lt;li&gt;Understand &lt;strong&gt;use cases&lt;/strong&gt; for the walrus operator&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoid repetitive code&lt;/strong&gt; by using the walrus operator&lt;/li&gt;
&lt;li&gt;Convert between code using the walrus operator and code using &lt;strong&gt;other assignment methods&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use appropriate &lt;strong&gt;style&lt;/strong&gt; in your assignment expressions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that all walrus operator examples in this tutorial require &lt;a href=&quot;https://realpython.com/python38-new-features/&quot;&gt;Python 3.8&lt;/a&gt; or later to work.&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-walrus-operator-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-walrus-operator-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 walrus operator.&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.1440a154cfa8.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “The Walrus Operator: Python&#x27;s Assignment Expressions” 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-walrus-operator/&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;The Walrus Operator: Python&#x27;s Assignment Expressions&quot; src=&quot;https://files.realpython.com/media/The-Walrus-Operator-in-Python-3.8-UPDATE_Watermarked.d7eee1fde3ea.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/The-Walrus-Operator-in-Python-3.8-UPDATE_Watermarked.d7eee1fde3ea.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/The-Walrus-Operator-in-Python-3.8-UPDATE_Watermarked.d7eee1fde3ea.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/The-Walrus-Operator-in-Python-3.8-UPDATE_Watermarked.d7eee1fde3ea.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/The-Walrus-Operator-in-Python-3.8-UPDATE_Watermarked.d7eee1fde3ea.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.1440a154cfa8.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-walrus-operator/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;The Walrus Operator: Python&#x27;s Assignment Expressions&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of the Python Walrus Operator. This operator was introduced in Python 3.8, and understanding it can help you write more concise and efficient code.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;walrus-operator-fundamentals&quot;&gt;Walrus Operator Fundamentals&lt;a class=&quot;headerlink&quot; href=&quot;#walrus-operator-fundamentals&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;First, look at some different terms that programmers use to refer to this new syntax. You’ve already seen a few in this tutorial.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;:=&lt;/code&gt; operator is officially known as the &lt;strong&gt;assignment expression operator&lt;/strong&gt;. During early discussions, it was dubbed the &lt;strong&gt;walrus operator&lt;/strong&gt; because the &lt;code&gt;:=&lt;/code&gt; syntax resembles the eyes and tusks of a &lt;a href=&quot;https://en.wikipedia.org/wiki/Walrus&quot;&gt;walrus&lt;/a&gt; lying on its side. You may also see the &lt;code&gt;:=&lt;/code&gt; operator referred to as the &lt;strong&gt;colon equals operator&lt;/strong&gt;. Yet another term used for assignment expressions is &lt;strong&gt;named expressions&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;hello-walrus&quot;&gt;Hello, Walrus!&lt;a class=&quot;headerlink&quot; href=&quot;#hello-walrus&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To get a first impression of what assignment expressions are all about, start your &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;REPL&lt;/a&gt; and play around with the following code:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;linenos&quot;&gt; 1&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;walrus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;walrus&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 3&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;False&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&lt;/span&gt;&lt;span class=&quot;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;n&quot;&gt;walrus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;True&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;True&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 7&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;walrus&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 8&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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.1440a154cfa8.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;Line 1 shows a traditional &lt;a href=&quot;https://docs.python.org/3/reference/simple_stmts.html#assignment-statements&quot;&gt;assignment statement&lt;/a&gt; where the value &lt;code&gt;False&lt;/code&gt; is assigned to &lt;code&gt;walrus&lt;/code&gt;. Next, on line 5, you use an assignment expression to assign the value &lt;code&gt;True&lt;/code&gt; to &lt;code&gt;walrus&lt;/code&gt;. After both lines 1 and 5, you can refer to the assigned values by using the &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variable&lt;/a&gt; name &lt;code&gt;walrus&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You might be wondering why you’re using parentheses on line 5, and you’ll learn why the parentheses are needed &lt;a href=&quot;#walrus-operator-syntax&quot;&gt;later on in this tutorial&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; A &lt;strong&gt;statement&lt;/strong&gt; in Python is a unit of code. An &lt;strong&gt;expression&lt;/strong&gt; is a special statement that can be evaluated to some value.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;1 + 2&lt;/code&gt; is an expression that evaluates to the value &lt;code&gt;3&lt;/code&gt;, while &lt;code&gt;number = 1 + 2&lt;/code&gt; is an assignment statement that doesn’t evaluate to a value. Although running the statement &lt;code&gt;number = 1 + 2&lt;/code&gt; doesn’t evaluate to &lt;code&gt;3&lt;/code&gt;, it does &lt;em&gt;assign&lt;/em&gt; the value &lt;code&gt;3&lt;/code&gt; to &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In Python, you often see &lt;a href=&quot;https://docs.python.org/3/reference/simple_stmts.html&quot;&gt;simple statements&lt;/a&gt; like &lt;a href=&quot;https://realpython.com/python-return-statement/&quot;&gt;&lt;code&gt;return&lt;/code&gt; statements&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-import/&quot;&gt;&lt;code&gt;import&lt;/code&gt; statements&lt;/a&gt;, as well as &lt;a href=&quot;https://docs.python.org/3/reference/compound_stmts.html&quot;&gt;compound statements&lt;/a&gt; like &lt;a href=&quot;https://realpython.com/python-conditional-statements/&quot;&gt;&lt;code&gt;if&lt;/code&gt; statements&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;function definitions&lt;/a&gt;. These are all statements, not expressions.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There’s a subtle—but important—difference between the two types of assignments with the &lt;code&gt;walrus&lt;/code&gt; variable. An assignment expression returns the value, while a traditional assignment doesn’t. You can see this in action when the REPL doesn’t print any value after &lt;code&gt;walrus = False&lt;/code&gt; on line 1 but prints out &lt;code&gt;True&lt;/code&gt; after the assignment expression on line 5.&lt;/p&gt;
&lt;p&gt;You can see another important aspect about walrus operators in this example. Though it might look new, the &lt;code&gt;:=&lt;/code&gt; operator does &lt;em&gt;not&lt;/em&gt; do anything that isn’t possible without it. It only makes certain constructs more convenient and can sometimes communicate the intent of your code more clearly.&lt;/p&gt;
&lt;p&gt;Now you have a basic idea of what the &lt;code&gt;:=&lt;/code&gt; operator is and what it can do. It’s an operator used in assignment expressions, which can return the value being assigned, unlike traditional assignment statements. To get deeper and really learn about the walrus operator, continue reading to see where you should and shouldn’t use it.&lt;/p&gt;
&lt;h3 id=&quot;implementation&quot;&gt;Implementation&lt;a class=&quot;headerlink&quot; href=&quot;#implementation&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Like most new features in Python, assignment expressions were introduced through a &lt;strong&gt;Python Enhancement Proposal&lt;/strong&gt; (PEP). &lt;a href=&quot;https://www.python.org/dev/peps/pep-0572&quot;&gt;PEP 572&lt;/a&gt; describes the motivation for introducing the walrus operator, the details of the syntax, and examples where the &lt;code&gt;:=&lt;/code&gt; operator can be used to improve your code.&lt;/p&gt;
&lt;p&gt;This PEP was &lt;a href=&quot;https://mail.python.org/archives/list/python-ideas@python.org/message/H64ZNZ3T4RRJKMXR6UFNX3FK62IRPVOT/&quot;&gt;originally&lt;/a&gt; written by &lt;a href=&quot;https://twitter.com/Rosuav&quot;&gt;Chris Angelico&lt;/a&gt; in February 2018. Following some heated discussion, PEP 572 was &lt;a href=&quot;https://mail.python.org/archives/list/python-dev@python.org/message/J6EBK6ZEHZXTVWYSUO5N5XCUS45UQSB3/&quot;&gt;accepted&lt;/a&gt; by &lt;a href=&quot;https://twitter.com/gvanrossum&quot;&gt;Guido van Rossum&lt;/a&gt; in July 2018.&lt;/p&gt;
&lt;p&gt;Since then, Guido &lt;a href=&quot;https://mail.python.org/archives/list/python-committers@python.org/message/GQONAGWBBFRHVRUPU7RNBM75MHKGUFJN/&quot;&gt;announced&lt;/a&gt; that he was stepping down from his role as &lt;a href=&quot;https://en.wikipedia.org/wiki/Benevolent_dictator_for_life&quot;&gt;benevolent dictator for life (BDFL)&lt;/a&gt;. Since early 2019, the Python language has been &lt;a href=&quot;https://www.python.org/dev/peps/pep-0013/&quot;&gt;governed&lt;/a&gt; by an elected &lt;a href=&quot;https://realpython.com/python38-new-features/#the-python-steering-council&quot;&gt;steering council&lt;/a&gt; instead.&lt;/p&gt;
&lt;p&gt;The walrus operator was implemented by &lt;a href=&quot;https://realpython.com/interview-emily-morehouse/&quot;&gt;Emily Morehouse&lt;/a&gt;, and made available in the first &lt;a href=&quot;https://www.python.org/downloads/release/python-380a1/&quot;&gt;alpha release&lt;/a&gt; of Python 3.8.&lt;/p&gt;
&lt;h3 id=&quot;motivation&quot;&gt;Motivation&lt;a class=&quot;headerlink&quot; href=&quot;#motivation&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-walrus-operator/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-walrus-operator/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: The Walrus Operator: Python&#x27;s Assignment Expressions</title>
      <id>https://realpython.com/quizzes/python-walrus-operator/</id>
      <link href="https://realpython.com/quizzes/python-walrus-operator/"/>
      <updated>2024-08-14T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of the Python Walrus Operator. This operator was introduced in Python 3.8, and understanding it can help you write more concise and efficient code.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the &lt;a href=&quot;https://realpython.com/python-walrus-operator/&quot;&gt;Python Walrus Operator&lt;/a&gt;. This operator, used for assignment expressions, was introduced in Python 3.8 and can be used to assign values to variables as part of an expression.&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>Sorting Dictionaries in Python: Keys, Values, and More</title>
      <id>https://realpython.com/courses/sorting-dictionaries-keys-values-more/</id>
      <link href="https://realpython.com/courses/sorting-dictionaries-keys-values-more/"/>
      <updated>2024-08-13T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to sort Python dictionaries. By the end, you&#x27;ll be able to sort by key, value, or even nested attributes. But you won&#x27;t stop there---you&#x27;ll also measure the performance of variations when sorting and compare different key-value data structures.</summary>
      <content type="html">
        &lt;p&gt;You&amp;rsquo;ve got a &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt;, but you&amp;rsquo;d like to sort the key-value pairs. Perhaps you&amp;rsquo;ve tried passing a dictionary to the &lt;code&gt;sorted()&lt;/code&gt; &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;function&lt;/a&gt; but didn&amp;rsquo;t receive the results you expected. In this video course, you&amp;rsquo;ll go over everything you need to know to sort dictionaries in Python.&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;Review how to use the &lt;strong&gt;&lt;code&gt;sorted()&lt;/code&gt;&lt;/strong&gt; function&lt;/li&gt;
&lt;li&gt;Learn how to get dictionary &lt;strong&gt;views&lt;/strong&gt; to &lt;strong&gt;iterate&lt;/strong&gt; over&lt;/li&gt;
&lt;li&gt;Understand how dictionaries are cast to &lt;strong&gt;lists&lt;/strong&gt; during sorting&lt;/li&gt;
&lt;li&gt;Learn how to specify a &lt;strong&gt;sort key&lt;/strong&gt; to sort a dictionary by value, key, or nested attribute&lt;/li&gt;
&lt;li&gt;Review dictionary &lt;strong&gt;comprehensions&lt;/strong&gt; and the &lt;code&gt;dict()&lt;/code&gt; &lt;strong&gt;constructor&lt;/strong&gt; to rebuild your dictionaries&lt;/li&gt;
&lt;li&gt;Consider alternative &lt;strong&gt;data structures&lt;/strong&gt; for your &lt;strong&gt;key-value data&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 Roundup: August 2024</title>
      <id>https://realpython.com/python-news-august-2024/</id>
      <link href="https://realpython.com/python-news-august-2024/"/>
      <updated>2024-08-12T14:00:00+00:00</updated>
      <summary>In July 2024, Python published the first release candidate of its 3.13 version. The PSF announced some news about new staff members, and PyOhio US 2024 took place in Ohio. Finally, some fundamental Python projects, such as Django, Pillow, pytest, and Pydantic, also released new versions.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In July, there was some exciting news for the Python community as the Python core development team released versions 3.13.0b4 and 3.13.0rc1 of the language. The 3.13.0b4 release marked the end of the beta phase and paved the way for the release candidate phase.&lt;/p&gt;
&lt;p&gt;Note that 3.13.0rc1 is a pre-release, so you shouldn’t use it for production environments. However, it provides a great way to try some new and exciting language features.&lt;/p&gt;
&lt;p&gt;There’s also great some news from the Python Software Foundation, PyOhio 2024, and the Python ecosystem.&lt;/p&gt;
&lt;p&gt;Let’s dive into the most exciting &lt;strong&gt;Python news&lt;/strong&gt; from last month!&lt;/p&gt;
&lt;h2 id=&quot;python-3130b4-and-3130rc1&quot;&gt;Python 3.13.0b4 and 3.13.0rc1&lt;a class=&quot;headerlink&quot; href=&quot;#python-3130b4-and-3130rc1&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python 3.13 has reached its fourth beta release, marking the end of the beta phase. Beta releases serve to test new features and bug fixes. However, it’s important to note that this is a preview release and it isn’t recommended for use in production environments.&lt;/p&gt;
&lt;p&gt;If you’re a library maintainer, you’re encouraged to test your code with this new version so you can prepare it to support the latest features of the language.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To learn more about pre-releases, check out the &lt;a href=&quot;https://realpython.com/python-pre-release/&quot;&gt;How Can You Install a Pre-Release Version of Python?&lt;/a&gt; tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;One of the most significant new features of Python 3.13 is the improved interactive interpreter or &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;REPL&lt;/a&gt;, which now provides several cool features, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Colorized prompts&lt;/li&gt;
&lt;li&gt;Multiline editing with history preservation&lt;/li&gt;
&lt;li&gt;Interactive help browsing with &lt;span class=&quot;keys&quot;&gt;&lt;kbd class=&quot;key-f1&quot;&gt;F1&lt;/kbd&gt;&lt;/span&gt; and a separate command history&lt;/li&gt;
&lt;li&gt;History browsing with &lt;span class=&quot;keys&quot;&gt;&lt;kbd class=&quot;key-f2&quot;&gt;F2&lt;/kbd&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Paste mode for larger blocks of code with &lt;span class=&quot;keys&quot;&gt;&lt;kbd class=&quot;key-f3&quot;&gt;F3&lt;/kbd&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;REPL-specific commands like &lt;code&gt;help&lt;/code&gt;, &lt;code&gt;exit&lt;/code&gt;, and &lt;code&gt;quit&lt;/code&gt; without the call parentheses&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is exciting news! The standard REPL up until Python 3.13 was lacking, and sometimes it was necessary to install a third-party tool like &lt;a href=&quot;https://realpython.com/bpython-alternative-python-repl/&quot;&gt;bpython&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/ipython-interactive-python-shell/&quot;&gt;IPython&lt;/a&gt; to compensate.&lt;/p&gt;
&lt;p&gt;Again, with this release, the beta phase has officially ended, and the first release candidate—3.13.0rc1—is considered the penultimate release preview. In this release candidate phase, only bug fixes are allowed.&lt;/p&gt;
&lt;p&gt;The second candidate, which is the last planned release preview, should be out on September 3, 2024, and the official release of 3.13 should be ready on October 1, 2024. Only more excitement lies ahead! &lt;/p&gt;
&lt;h2 id=&quot;the-python-software-foundation-psf-shares-great-news&quot;&gt;The Python Software Foundation (PSF) Shares Great News&lt;a class=&quot;headerlink&quot; href=&quot;#the-python-software-foundation-psf-shares-great-news&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-august-2024/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-august-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 #216: Learning Through Building the Black Python Devs Community</title>
      <id>https://realpython.com/podcasts/rpp/216/</id>
      <link href="https://realpython.com/podcasts/rpp/216/"/>
      <updated>2024-08-09T12:00:00+00:00</updated>
      <summary>What hurdles must be cleared when starting an international organization? How do you empower others in a community by sharing responsibilities? This week on the show, we speak with Jay Miller about Black Python Devs.</summary>
      <content type="html">
        &lt;p&gt;What hurdles must be cleared when starting an international organization? How do you empower others in a community by sharing responsibilities? This week on the show, we speak with Jay Miller about Black Python Devs.&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>Asynchronous Iterators and Iterables in Python</title>
      <id>https://realpython.com/python-async-iterators/</id>
      <link href="https://realpython.com/python-async-iterators/"/>
      <updated>2024-08-07T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to create and use asynchronous iterators and iterables in Python. You&#x27;ll explore their syntax and structure and discover how they can be leveraged to handle asynchronous operations more efficiently.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;When you write asynchronous code in Python, you’ll likely need to create asynchronous iterators and iterables at some point. Asynchronous iterators are what Python uses to control &lt;code&gt;async for&lt;/code&gt; loops, while asynchronous iterables are objects that you can iterate over using &lt;code&gt;async for&lt;/code&gt; loops.&lt;/p&gt;
&lt;p&gt;Both tools allow you to iterate over awaitable objects without blocking your code. This way, you can perform different tasks asynchronously.&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;Learn what &lt;strong&gt;async iterators&lt;/strong&gt; and &lt;strong&gt;iterables&lt;/strong&gt; are in Python&lt;/li&gt;
&lt;li&gt;Create async &lt;strong&gt;generator expressions&lt;/strong&gt; and &lt;strong&gt;generator iterators&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Code async iterators and iterables with the &lt;strong&gt;&lt;code&gt;.__aiter__()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;.__anext__()&lt;/code&gt;&lt;/strong&gt; methods&lt;/li&gt;
&lt;li&gt;Use async iterators in &lt;strong&gt;async loops&lt;/strong&gt; and &lt;strong&gt;comprehensions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should know the basics of Python’s &lt;a href=&quot;https://realpython.com/python-iterators-iterables/&quot;&gt;iterators and iterables&lt;/a&gt;. You should also know about Python’s &lt;a href=&quot;https://realpython.com/python-async-features/&quot;&gt;asynchronous features&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/async-io-python/&quot;&gt;tools&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-async-iterators/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-async-iterators&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to learn about asynchronous iterators and iterables 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.1440a154cfa8.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 “Asynchronous Iterators and Iterables 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-async-iterators/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #b9abe6;&quot; alt=&quot;Asynchronous Iterators and Iterables in Python&quot; src=&quot;https://files.realpython.com/media/Asynchronous-Iterators-and-Iterables-in-Python_Watermarked.c7ed7ce35df8.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Asynchronous-Iterators-and-Iterables-in-Python_Watermarked.c7ed7ce35df8.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Asynchronous-Iterators-and-Iterables-in-Python_Watermarked.c7ed7ce35df8.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Asynchronous-Iterators-and-Iterables-in-Python_Watermarked.c7ed7ce35df8.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Asynchronous-Iterators-and-Iterables-in-Python_Watermarked.c7ed7ce35df8.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.1440a154cfa8.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-async-iterators/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Asynchronous Iterators and Iterables in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Take this quiz to test your understanding of how to create and use Python async iterators and iterables in the context of asynchronous code.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-async-iterators-and-iterables-in-python&quot;&gt;Getting to Know Async Iterators and Iterables in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-async-iterators-and-iterables-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Iterators and iterables are fundamental components in Python. You’ll use them in almost all your programs where you iterate over data streams using a &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt; loop&lt;/a&gt;. Iterators power and control the iteration process, while iterables typically hold data that you want to iterate over.&lt;/p&gt;
&lt;p&gt;Python iterators implement the &lt;a href=&quot;https://en.wikipedia.org/wiki/Iterator_pattern&quot;&gt;iterator design pattern&lt;/a&gt;, which allows you to traverse a container and access its elements. To implement this pattern, iterators need the &lt;code&gt;.__iter__()&lt;/code&gt; and &lt;code&gt;.__next__()&lt;/code&gt; &lt;a href=&quot;https://realpython.com/python-magic-methods/&quot;&gt;special methods&lt;/a&gt;. Similarly, iterables are typically data containers that implement the &lt;code&gt;.__iter__()&lt;/code&gt; method.&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 iterators and iterables, check out the &lt;a href=&quot;https://realpython.com/python-iterators-iterables/&quot;&gt;Iterators and Iterables in Python: Run Efficient Iterations&lt;/a&gt; tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Python has extended the concept of iterators and iterables to &lt;strong&gt;asynchronous programming&lt;/strong&gt; with the &lt;code&gt;asyncio&lt;/code&gt; module and the &lt;a href=&quot;https://realpython.com/python-keywords/#asynchronous-programming-keywords-async-await&quot;&gt;&lt;code&gt;async&lt;/code&gt; and &lt;code&gt;await&lt;/code&gt;&lt;/a&gt; keywords. In this scenario, asynchronous iterators drive the &lt;strong&gt;asynchronous iteration process&lt;/strong&gt;, mainly powered by &lt;code&gt;async for&lt;/code&gt; loops and &lt;a href=&quot;#asynchronous-comprehensions-and-generator-expressions&quot;&gt;comprehensions&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; In this tutorial, you won’t dive into the intricacies of Python’s asynchronous programming. So, you should be familiar with the related concepts. If you’re not, then you can check out the following tutorials:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/python-async-features/&quot;&gt;Getting Started With Async Features in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/async-io-python/&quot;&gt;Async IO in Python: A Complete Walkthrough&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In these tutorials, you’ll gain the required background to prepare for exploring asynchronous iterators and iterables in more depth.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the following sections, you’ll briefly examine the concepts of asynchronous iterators and iterables in Python.&lt;/p&gt;
&lt;h3 id=&quot;async-iterators&quot;&gt;Async Iterators&lt;a class=&quot;headerlink&quot; href=&quot;#async-iterators&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Python’s documentation defines &lt;strong&gt;asynchronous iterators&lt;/strong&gt;, or &lt;em&gt;async iterators&lt;/em&gt; for short, as the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An object that implements the &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html#object.__aiter__&quot;&gt;&lt;code&gt;.__aiter__()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html#object.__anext__&quot;&gt;&lt;code&gt;.__anext__()&lt;/code&gt;&lt;/a&gt; [special] methods. &lt;code&gt;.__anext__()&lt;/code&gt; must return an &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-awaitable&quot;&gt;awaitable&lt;/a&gt; object. [An] &lt;a href=&quot;https://docs.python.org/3/reference/compound_stmts.html#async-for&quot;&gt;&lt;code&gt;async for&lt;/code&gt;&lt;/a&gt; [loop] resolves the awaitables returned by an asynchronous iterator’s &lt;code&gt;.__anext__()&lt;/code&gt; method until it raises a &lt;a href=&quot;https://docs.python.org/3/library/exceptions.html#StopAsyncIteration&quot;&gt;&lt;code&gt;StopAsyncIteration&lt;/code&gt;&lt;/a&gt; exception. (&lt;a href=&quot;https://docs.python.org/3/glossary.html#term-asynchronous-iterator&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Similar to regular iterators that must implement &lt;code&gt;.__iter__()&lt;/code&gt; and &lt;code&gt;.__next__()&lt;/code&gt;, async iterators must implement &lt;code&gt;.__aiter__()&lt;/code&gt; and &lt;code&gt;.__anext__()&lt;/code&gt;. In regular iterators, the &lt;code&gt;.__iter__()&lt;/code&gt; method usually returns the iterator itself. This is also true for async iterators.&lt;/p&gt;
&lt;p&gt;To continue with this parallelism, in regular iterators, the &lt;code&gt;.__next__()&lt;/code&gt; method must return the next object for the iteration. In async iterators, the &lt;code&gt;.__anext__()&lt;/code&gt; method must return the next object, which must be awaitable.&lt;/p&gt;
&lt;p&gt;Python defines awaitable objects as described in the quote below:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An object that can be used in an &lt;a href=&quot;https://docs.python.org/3/reference/expressions.html#await&quot;&gt;&lt;code&gt;await&lt;/code&gt;&lt;/a&gt; expression. [It] can be a &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-coroutine&quot;&gt;coroutine&lt;/a&gt; or an object with an &lt;a href=&quot;https://docs.python.org/3/reference/datamodel.html#object.__await__&quot;&gt;&lt;code&gt;.__await__()&lt;/code&gt;&lt;/a&gt; method. (&lt;a href=&quot;https://docs.python.org/3/glossary.html#term-awaitable&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In practice, a quick way to make an awaitable object in Python is to call an asynchronous function. You define this type of function with the &lt;a href=&quot;https://docs.python.org/3/reference/compound_stmts.html#async-def&quot;&gt;&lt;code&gt;async def&lt;/code&gt;&lt;/a&gt; keyword construct. This call creates a &lt;strong&gt;coroutine object&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can also create awaitable objects by implementing the &lt;code&gt;.__await__()&lt;/code&gt; special method in a custom class. This method must return an &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-iterator&quot;&gt;iterator&lt;/a&gt; that yields control back to the &lt;a href=&quot;https://docs.python.org/3/library/asyncio-eventloop.html&quot;&gt;event loop&lt;/a&gt; until the awaited result is ready. This topic is beyond the scope of this tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;When the data stream runs out of data, the method must raise a &lt;code&gt;StopAsyncIteration&lt;/code&gt; exception to end the asynchronous iteration process.&lt;/p&gt;
&lt;p&gt;Here’s an example of an async iterator that allows iterating over a range of numbers asynchronously:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-async-iterators/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-async-iterators/ »&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: Asynchronous Iterators and Iterables in Python</title>
      <id>https://realpython.com/quizzes/python-async-iterators/</id>
      <link href="https://realpython.com/quizzes/python-async-iterators/"/>
      <updated>2024-08-07T12:00:00+00:00</updated>
      <summary>Take this quiz to test your understanding of how to create and use Python async iterators and iterables in the context of asynchronous code.</summary>
      <content type="html">
        &lt;p&gt;Test your understanding of how to create and use Python async iterators and iterables in the context of asynchronous code.&lt;/p&gt;
&lt;p&gt;You can take this quiz after reading the &lt;a href=&quot;https://realpython.com/python-async-iterators/&quot;&gt;Asynchronous Iterators and Iterables in Python&lt;/a&gt; tutorial.&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>Interacting With REST APIs and Python</title>
      <id>https://realpython.com/courses/interacting-rest-apis-python/</id>
      <link href="https://realpython.com/courses/interacting-rest-apis-python/"/>
      <updated>2024-08-06T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to use Python to communicate with REST APIs. You&#x27;ll learn about REST architecture and how to use the requests library to get data from a REST API. You&#x27;ll also explore different Python tools you can use to build REST APIs.</summary>
      <content type="html">
        &lt;p&gt;There&amp;rsquo;s an amazing amount of data available on the Web. Many &lt;strong&gt;web services&lt;/strong&gt;, like YouTube and GitHub, make their data accessible to third-party applications through an &lt;strong&gt;application programming interface (API)&lt;/strong&gt;. One of the most popular ways to build APIs is the &lt;strong&gt;REST&lt;/strong&gt; architecture style. Python provides some great tools not only to get data from REST APIs but also to build your own Python REST APIs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What &lt;strong&gt;REST&lt;/strong&gt; architecture is&lt;/li&gt;
&lt;li&gt;How &lt;strong&gt;REST APIs&lt;/strong&gt; provide access to web data&lt;/li&gt;
&lt;li&gt;How to consume data from REST APIs using the &lt;strong&gt;&lt;code&gt;requests&lt;/code&gt;&lt;/strong&gt; library&lt;/li&gt;
&lt;li&gt;What steps to take to &lt;strong&gt;build a REST API&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;What some popular &lt;strong&gt;Python tools&lt;/strong&gt; are for building REST APIs&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>Functional Programming in Python: When and How to Use It</title>
      <id>https://realpython.com/python-functional-programming/</id>
      <link href="https://realpython.com/python-functional-programming/"/>
      <updated>2024-08-05T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about functional programming in Python. You&#x27;ll see what functional programming is, how it&#x27;s supported in Python, and how you can use it in your Python code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;&lt;strong&gt;Functional programming&lt;/strong&gt; is a programming paradigm in which the primary method of computation is the evaluation of functions. But how does Python support functional programming?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What the &lt;strong&gt;functional programming&lt;/strong&gt; paradigm entails&lt;/li&gt;
&lt;li&gt;What it means to say that &lt;strong&gt;functions&lt;/strong&gt; are &lt;strong&gt;first-class citizens&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;How to define &lt;strong&gt;anonymous functions&lt;/strong&gt; with the &lt;strong&gt;&lt;code&gt;lambda&lt;/code&gt;&lt;/strong&gt; keyword&lt;/li&gt;
&lt;li&gt;How to implement functional code using &lt;strong&gt;&lt;code&gt;map()&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;reduce()&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Functional programming typically plays a minor role in Python code, but it’s still good to be familiar with it. You’ll probably encounter it from time to time when reading code written by others. And you may even find situations where it’s advantageous to use Python’s functional programming capabilities in your own code.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-functional-programming-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-functional-programming-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 when and how to use  functional programming 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.1440a154cfa8.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 “Functional Programming in Python: When and How to Use It” 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-functional-programming/&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;Functional Programming in Python: When and How to Use It&quot; src=&quot;https://files.realpython.com/media/TUT19---Functional-Programming_Watermarked.7c5a8382c298.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/TUT19---Functional-Programming_Watermarked.7c5a8382c298.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/TUT19---Functional-Programming_Watermarked.7c5a8382c298.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/TUT19---Functional-Programming_Watermarked.7c5a8382c298.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/TUT19---Functional-Programming_Watermarked.7c5a8382c298.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.1440a154cfa8.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-functional-programming/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Functional Programming in Python: When and How to Use It&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 functional programming in Python. You&#x27;ll revisit concepts such as functions being first-class citizens in Python, the use of the lambda keyword, and the implementation of functional code using map(), filter(), and reduce().&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;what-is-functional-programming&quot;&gt;What Is Functional Programming?&lt;a class=&quot;headerlink&quot; href=&quot;#what-is-functional-programming&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A &lt;strong&gt;pure function&lt;/strong&gt; is a function whose output value follows solely from its input values without any observable &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/#side-effects&quot;&gt;side effects&lt;/a&gt;. In &lt;strong&gt;functional programming&lt;/strong&gt;, a program consists primarily of the evaluation of pure functions. Computation proceeds by nested or &lt;a href=&quot;https://en.wikipedia.org/wiki/Function_composition_(computer_science)&quot;&gt;composed function calls&lt;/a&gt; without changes to state or mutable data.&lt;/p&gt;
&lt;p&gt;The functional paradigm is popular because it offers several advantages over other programming paradigms. Functional code is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;High level:&lt;/strong&gt; You describe the result you want rather than explicitly specifying the steps required to get there. Single statements tend to be concise but pack a lot of punch.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transparent:&lt;/strong&gt; The behavior of a pure function can be described by its inputs and outputs, without intermediary values. This eliminates the possibility of side effects and facilitates &lt;a href=&quot;https://realpython.com/python-debugging-pdb/&quot;&gt;debugging&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parallelizable:&lt;/strong&gt; Routines that don’t cause side effects can more easily &lt;a href=&quot;https://realpython.com/learning-paths/python-concurrency-parallel-programming/&quot;&gt;run in parallel&lt;/a&gt; with one another.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Many programming languages support some degree of functional programming. In some languages, virtually all code follows the functional paradigm. &lt;a href=&quot;https://www.haskell.org&quot;&gt;Haskell&lt;/a&gt; is one such example. Python, by contrast, does support functional programming but contains features of other programming models as well.&lt;/p&gt;
&lt;p&gt;While it’s true that an in-depth description of &lt;a href=&quot;https://en.wikipedia.org/wiki/Functional_programming&quot;&gt;functional programming&lt;/a&gt; is somewhat complex, the goal here isn’t to present a rigorous definition but to show you what you can do by way of functional programming in Python.&lt;/p&gt;
&lt;h2 id=&quot;how-well-does-python-support-functional-programming&quot;&gt;How Well Does Python Support Functional Programming?&lt;a class=&quot;headerlink&quot; href=&quot;#how-well-does-python-support-functional-programming&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To support functional programming, it’s beneficial if a &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;function&lt;/a&gt; in a given programming language can do these two things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Take another function as an argument&lt;/li&gt;
&lt;li&gt;Return another function to its caller&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Python plays nicely in both respects. Everything in Python is an &lt;a href=&quot;https://realpython.com/python-variables/#object-references&quot;&gt;object&lt;/a&gt;, and all objects in Python have more or less equal stature. Functions are no exception.&lt;/p&gt;
&lt;p&gt;In Python, functions are &lt;strong&gt;first-class citizens&lt;/strong&gt;. This means that functions have the same characteristics as values like &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;strings&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-numbers/&quot;&gt;numbers&lt;/a&gt;. Anything you would expect to be able to do with a string or number, you can also do with a function.&lt;/p&gt;
&lt;p&gt;For example, you can assign a function to a variable. You can then use that variable the same way you would use the function itself:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 2&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;I am function func()!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 3&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 4&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 5&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;func&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;I am function func()!&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt; 7&lt;/span&gt;
&lt;span class=&quot;hll&quot;&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;n&quot;&gt;another_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;linenos&quot;&gt; 9&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;another_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;linenos&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;I am function func()!&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.1440a154cfa8.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.1440a154cfa8.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 assignment &lt;code&gt;another_name = func&lt;/code&gt; on line 8 creates a new reference to &lt;code&gt;func()&lt;/code&gt; named &lt;code&gt;another_name&lt;/code&gt;. You can then call the function by either of the two names, &lt;code&gt;func&lt;/code&gt; or &lt;code&gt;another_name&lt;/code&gt;, as shown on lines 5 and 9.&lt;/p&gt;
&lt;p&gt;You can display a function to the console with &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt;, include it as an element in a composite data object like a &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;list&lt;/a&gt;, or even use it as a &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionary&lt;/a&gt; key:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;I am function func()!&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;hll&quot;&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;cat&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;go&quot;&gt;cat &amp;lt;function func at 0x7f81b4d29bf8&amp;gt; 42&lt;/span&gt;

&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;cat&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;function func at 0x7f81b4d29bf8&amp;gt;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;objects&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]()&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;I am function func()!&lt;/span&gt;

&lt;span class=&quot;hll&quot;&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;cat&quot;&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;n&quot;&gt;func&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;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;2&lt;/span&gt;
&lt;/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.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, &lt;code&gt;func()&lt;/code&gt; appears in all the same contexts as the values &lt;code&gt;&quot;cat&quot;&lt;/code&gt; and &lt;code&gt;42&lt;/code&gt;, and the interpreter handles it just fine.&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; What you can or can’t do with an object in Python depends to some extent on context. Some operations work for certain object types but not for others. &lt;/p&gt;
&lt;p&gt;For example, you can add two integer objects or &lt;a href=&quot;https://realpython.com/python-string-concatenation/&quot;&gt;concatenate&lt;/a&gt; two string objects with the plus operator (&lt;code&gt;+&lt;/code&gt;), but the plus operator isn’t defined for function objects.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;For present purposes, what matters is that functions in Python satisfy the two criteria beneficial for functional programming listed above. You can pass a function to another function as an argument:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-functional-programming/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-functional-programming/ »&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: Functional Programming in Python: When and How to Use It</title>
      <id>https://realpython.com/quizzes/python-functional-programming/</id>
      <link href="https://realpython.com/quizzes/python-functional-programming/"/>
      <updated>2024-08-05T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of functional programming in Python. You&#x27;ll revisit concepts such as functions being first-class citizens in Python, the use of the lambda keyword, and the implementation of functional code using map(), filter(), and reduce().</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-functional-programming/&quot;&gt;Functional Programming in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit the functional programming paradigm, the concept of functions as first-class citizens in Python, the use of the &lt;code&gt;lambda&lt;/code&gt; keyword, and how to implement functional code using &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt;.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #215: Using GraphQL in Django With Strawberry &amp; Prototype Purgatory</title>
      <id>https://realpython.com/podcasts/rpp/215/</id>
      <link href="https://realpython.com/podcasts/rpp/215/"/>
      <updated>2024-08-02T12:00:00+00:00</updated>
      <summary>How do you integrate GraphQL into your Python web development? How about quickly building graph-based APIs inside Django&#x27;s battery-included framework? 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 integrate GraphQL into your Python web development? How about quickly building graph-based APIs inside Django&#x27;s battery-included framework? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>How to Write an Installable Django App</title>
      <id>https://realpython.com/installable-django-app/</id>
      <link href="https://realpython.com/installable-django-app/"/>
      <updated>2024-07-31T14:00:00+00:00</updated>
      <summary>In this step-by-step tutorial, you&#x27;ll learn how to create an installable Django app. You&#x27;ll cover everything you need to know, from extracting your app from a Django project to turning it into a package that&#x27;s available on PyPI and installable through pip.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In the &lt;a href=&quot;https://realpython.com/get-started-with-django-1/&quot;&gt;Django&lt;/a&gt; framework, a &lt;strong&gt;project&lt;/strong&gt; refers to the collection of configuration files and code for a particular website. Django groups business logic into what it calls &lt;strong&gt;apps&lt;/strong&gt;, which are the modules of the Django framework. There’s plenty of documentation on how to structure your projects and the apps within them, but when it comes time to package an installable Django app, information is harder to find.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll learn how to take an app out of a &lt;a href=&quot;https://realpython.com/django-setup/&quot;&gt;Django project&lt;/a&gt; and package it so that it’s installable. Once you’ve packaged your app, you can share it on &lt;a href=&quot;https://pypi.org/&quot;&gt;PyPI&lt;/a&gt; so that others can fetch it through &lt;code&gt;pip&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What the differences are between writing &lt;strong&gt;stand-alone apps&lt;/strong&gt; and writing &lt;strong&gt;apps inside of projects&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to create a &lt;strong&gt;&lt;code&gt;pyproject.toml&lt;/code&gt; file&lt;/strong&gt; for publishing your Django app&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;bootstrap Django&lt;/strong&gt; outside of a Django project so you can test your app&lt;/li&gt;
&lt;li&gt;How to test across multiple versions of Python and Django using &lt;strong&gt;&lt;code&gt;nox&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to publish your installable Django app to PyPI using &lt;strong&gt;Twine&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This tutorial includes a working package to help guide you through the process of making an installable Django app. You can download the source code by clicking the link below:&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/installable-django-app-update-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-installable-django-app-update-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 write an installable Django app.&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;This tutorial requires some familiarity with &lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt;, &lt;a href=&quot;https://pip.pypa.io/&quot;&gt;&lt;code&gt;pip&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://pypi.org&quot;&gt;PyPI&lt;/a&gt;, &lt;a href=&quot;https://github.com/pyenv/pyenv&quot;&gt;&lt;code&gt;pyenv&lt;/code&gt;&lt;/a&gt;—or an equivalent virtual environment tool—and &lt;a href=&quot;https://nox.thea.codes/&quot;&gt;&lt;code&gt;nox&lt;/code&gt;&lt;/a&gt;. To learn more about these, you can check out the following resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/tutorials/django/&quot;&gt;Django Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/what-is-pip/&quot;&gt;Using Python’s pip to Manage Your Projects’ Dependencies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/pypi-publish-python-package/&quot;&gt;How to Publish an Open-Source Python Package to PyPI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://realpython.com/intro-to-pyenv/&quot;&gt;Managing Multiple Python Versions With pyenv&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;starting-a-sample-django-app-in-a-project&quot;&gt;Starting a Sample Django App in a Project&lt;a class=&quot;headerlink&quot; href=&quot;#starting-a-sample-django-app-in-a-project&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Even if you set out to make your Django app available as a package, you’ll likely start inside a project. In the sample code, you’ll find a &lt;code&gt;000_before&lt;/code&gt; directory that shows the code before the app is moved onto its own, demonstrating the process of transitioning from a Django project to an installable Django app.  &lt;/p&gt;
&lt;p&gt;You can also download the finished app at the &lt;a href=&quot;https://pypi.org/project/realpython-django-receipts/&quot;&gt;PyPI realpython-django-receipts&lt;/a&gt; package page, or install the package by running &lt;code&gt;python -m pip install realpython-django-receipts&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The sample app is a short representation of the line items on a receipt. In the &lt;code&gt;000_before&lt;/code&gt; folder, you’ll find a directory named &lt;code&gt;sample_project&lt;/code&gt; that contains a working Django project:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sample_project/
│
├── receipts/
│   ├── fixtures/
│   │   └── receipts.json
│   │
│   ├── migrations/
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   │
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
│
├── sample_project/
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
│
├── db.sqlite3
├── manage.py
├── resetdb.sh
└── runserver.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This tutorial was written using Django 5.0.7 and it was tested with Python 3.8 through 3.12. All of the steps outlined in this tutorial should be compatible with earlier versions of Django going back to Django 1.8. However, some modifications will be necessary if you’re using Python 2. For simplicity, the examples in this tutorial assume at least Python 3.8 across the code base.&lt;/p&gt;
&lt;h3 id=&quot;creating-the-django-project-from-scratch&quot;&gt;Creating the Django Project From Scratch&lt;a class=&quot;headerlink&quot; href=&quot;#creating-the-django-project-from-scratch&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The sample project and receipts app were created using the Django &lt;code&gt;admin&lt;/code&gt; command and some small edits. To start, run the following code inside of a clean virtual environment:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;console&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--yellow&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Shell&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Django
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;django-admin&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;startproject&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;sample_project
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;sample_project
&lt;span class=&quot;gp&quot;&gt;$ &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;manage.py&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;startapp&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;receipts
&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.1440a154cfa8.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.1440a154cfa8.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 creates the &lt;code&gt;sample_project&lt;/code&gt; project directory structure and a &lt;code&gt;receipts&lt;/code&gt; app subdirectory with template files that you’ll use to create your installable Django app.&lt;/p&gt;
&lt;p&gt;Next, the &lt;code&gt;sample_project/settings.py&lt;/code&gt; file needs a few modifications:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add &lt;code&gt;&quot;127.0.0.1&quot;&lt;/code&gt; to the &lt;code&gt;ALLOWED_HOSTS&lt;/code&gt; setting so you can test locally.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;&quot;receipts&quot;&lt;/code&gt; to the &lt;code&gt;INSTALLED_APPS&lt;/code&gt; list.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll also need to register the &lt;code&gt;receipts&lt;/code&gt; app’s URLs in the &lt;code&gt;sample_project/urls.py&lt;/code&gt; file. To do so, add &lt;code&gt;path(&quot;receipts/&quot;, include(&quot;receipts.urls&quot;))&lt;/code&gt; to the &lt;code&gt;url_patterns&lt;/code&gt; list. Note that you’ll need to add the &lt;code&gt;include&lt;/code&gt; function as an import from &lt;code&gt;django.urls&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;exploring-the-receipts-sample-app&quot;&gt;Exploring the Receipts Sample App&lt;a class=&quot;headerlink&quot; href=&quot;#exploring-the-receipts-sample-app&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The app consists of two ORM model classes: &lt;code&gt;Item&lt;/code&gt; and &lt;code&gt;Receipt&lt;/code&gt;. The &lt;code&gt;Item&lt;/code&gt; class contains database field declarations for a description and a cost. The cost is contained in a &lt;a href=&quot;https://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield&quot;&gt;&lt;code&gt;DecimalField&lt;/code&gt;&lt;/a&gt;. It’s never a good idea to use floating-point numbers to represent money. Instead, you should always use &lt;a href=&quot;https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency&quot;&gt;fixed-point numbers&lt;/a&gt; when dealing with currencies.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;Receipt&lt;/code&gt; class is a collection point for &lt;code&gt;Item&lt;/code&gt; objects. This is achieved with a &lt;code&gt;ForeignKey&lt;/code&gt; on &lt;code&gt;Item&lt;/code&gt; that points to &lt;code&gt;Receipt&lt;/code&gt;. &lt;code&gt;Receipt&lt;/code&gt; also includes &lt;code&gt;total()&lt;/code&gt; for getting the total cost of &lt;code&gt;Item&lt;/code&gt; objects contained in the &lt;code&gt;Receipt&lt;/code&gt;:&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/installable-django-app/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/installable-django-app/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python&#x27;s Built-in Exceptions: A Walkthrough With Examples</title>
      <id>https://realpython.com/quizzes/python-built-in-exceptions/</id>
      <link href="https://realpython.com/quizzes/python-built-in-exceptions/"/>
      <updated>2024-07-31T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s built-in exceptions. With this knowledge, you&#x27;ll be able to effectively identify and handle these exceptions when they appear. Additionally, you&#x27;ll be more familiar with how to raise some of these exceptions in your code.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of the most commonly used &lt;a href=&quot;https://realpython.com/python-built-in-exceptions/&quot;&gt;built-in exceptions in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Exception handling is a core topic in Python. Knowing how to use some of the most common built-in exceptions can help you to debug your code and handle your own exceptions.&lt;/p&gt;
&lt;p&gt;Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Simulate a Text File in Python</title>
      <id>https://realpython.com/courses/simulate-text-file/</id>
      <link href="https://realpython.com/courses/simulate-text-file/"/>
      <updated>2024-07-30T14:00:00+00:00</updated>
      <summary>Testing an application that reads files from a disk can be complicated. It may depend on the machine, require special access, or be frustratingly slow. This course shows you how to simulate a text file using Python to simplify testing.</summary>
      <content type="html">
        &lt;p&gt;Testing applications that read files from a disk can be challenging. Issues such as machine dependencies, special access requirements, and slow performance often arise when you need to read text from a file.&lt;/p&gt;
&lt;p&gt;In this &lt;strong&gt;Code Conversation&lt;/strong&gt; with instructor Martin Breuss, you&amp;rsquo;ll discover how to simplify this process by simulating text files with StringIO from the io module in Python’s standard library.&lt;/p&gt;
&lt;p&gt;In this video course, you’ll learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;io.StringIO&lt;/code&gt; to simulate a text file on disk&lt;/li&gt;
&lt;li&gt;Perform file operations on a &lt;code&gt;io.StringIO&lt;/code&gt; object&lt;/li&gt;
&lt;li&gt;Decide when to use &lt;code&gt;io.StringIO&lt;/code&gt; and when to avoid it&lt;/li&gt;
&lt;li&gt;Understand possible alternatives&lt;/li&gt;
&lt;li&gt;Mock a file object using &lt;code&gt;unittest.mock&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding how to simulate text file objects and mock file objects can help streamline your testing strategy and development process.&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>Strings and Character Data in Python</title>
      <id>https://realpython.com/python-strings/</id>
      <link href="https://realpython.com/python-strings/"/>
      <updated>2024-07-29T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use Python&#x27;s rich set of operators and functions for working with strings. You&#x27;ll cover the basics of creating strings using literals and the str() function, applying string methods, using operators and built-in functions with strings, and more!</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In Python, &lt;strong&gt;string&lt;/strong&gt; objects contain sequences of characters that allow you to manipulate textual data. It’s rare to find an application, program, or library that doesn’t need to manipulate strings to some extent. So, processing characters and strings is integral to programming and a fundamental skill for you as a Python programmer.&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;Create strings using &lt;strong&gt;literals&lt;/strong&gt; and the &lt;strong&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/strong&gt; function&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;operators&lt;/strong&gt; and &lt;strong&gt;built-in functions&lt;/strong&gt; with strings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Index&lt;/strong&gt; and &lt;strong&gt;slice&lt;/strong&gt; strings&lt;/li&gt;
&lt;li&gt;Do string &lt;strong&gt;interpolation&lt;/strong&gt; and &lt;strong&gt;formatting&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Use string &lt;strong&gt;methods&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should have a good understanding of core Python concepts, including &lt;a href=&quot;https://realpython.com/python-variables/&quot;&gt;variables&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;functions&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-operators-expressions/&quot;&gt;operators and expressions&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-string-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-string-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 work with strings and character data 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.1440a154cfa8.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 Strings and Character Data” 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-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: #abe0e6;&quot; alt=&quot;Strings and Character Data in Python&quot; src=&quot;https://files.realpython.com/media/Strings-and-Character-Data-in-Python_Watermarked.797803948b10.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Strings-and-Character-Data-in-Python_Watermarked.797803948b10.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Strings-and-Character-Data-in-Python_Watermarked.797803948b10.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Strings-and-Character-Data-in-Python_Watermarked.797803948b10.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Strings-and-Character-Data-in-Python_Watermarked.797803948b10.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.1440a154cfa8.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-strings/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python Strings and Character Data&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;This quiz will test your understanding of Python&#x27;s string data type and your knowledge about manipulating textual data with string objects. You&#x27;ll cover the basics of creating strings using literals and the str() function, applying string methods, using operators and built-in functions, and more!&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;getting-to-know-strings-and-characters-in-python&quot;&gt;Getting to Know Strings and Characters in Python&lt;a class=&quot;headerlink&quot; href=&quot;#getting-to-know-strings-and-characters-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python provides the &lt;a href=&quot;https://realpython.com/python-data-types/#strings-and-characters&quot;&gt;built-in string (&lt;code&gt;str&lt;/code&gt;)&lt;/a&gt; data type to handle textual data. Other programming languages, such as &lt;a href=&quot;https://realpython.com/java-vs-python/&quot;&gt;Java&lt;/a&gt;, have a character data type for single characters. Python doesn’t have that. Single characters are strings of length one.&lt;/p&gt;
&lt;p&gt;In practice, strings are &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/#immutable-built-in-data-types-in-python&quot;&gt;immutable&lt;/a&gt; sequences of characters. This means you can’t change a string once you define it. Any operation that modifies a string will create a new string instead of modifying the original one.&lt;/p&gt;
&lt;p&gt;A string is also a &lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;sequence&lt;/a&gt;, which means that the characters in a string have a consecutive order. This feature allows you to access characters using integer indices that start with &lt;code&gt;0&lt;/code&gt;. You’ll learn more about these concepts in the section about &lt;a href=&quot;#indexing-strings&quot;&gt;indexing strings&lt;/a&gt;. For now, you’ll learn about how to create strings in Python.&lt;/p&gt;
&lt;h2 id=&quot;creating-strings-in-python&quot;&gt;Creating Strings in Python&lt;a class=&quot;headerlink&quot; href=&quot;#creating-strings-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;There are different ways to create strings in Python. The most common practice is to use string &lt;a href=&quot;https://docs.python.org/3/reference/lexical_analysis.html#literals&quot;&gt;literals&lt;/a&gt;. Because strings are everywhere and have many use cases, you’ll find a few different types of string literals. There are standard literals, raw literals, and formatted literals.&lt;/p&gt;
&lt;p&gt;Additionally, you can use the built-in &lt;code&gt;str()&lt;/code&gt; function to create new strings from other existing objects.&lt;/p&gt;
&lt;p&gt;In the following sections, you’ll learn about the multiple ways to create strings in Python and when to use each of them.&lt;/p&gt;
&lt;h3 id=&quot;standard-string-literals&quot;&gt;Standard String Literals&lt;a class=&quot;headerlink&quot; href=&quot;#standard-string-literals&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A standard string literal is just a piece of text or a &lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;sequence&lt;/a&gt; of characters that you enclose in quotes. To create single-line strings, you can use single (&lt;code&gt;&#x27;&#x27;&lt;/code&gt;) and double (&lt;code&gt;&quot;&quot;&lt;/code&gt;) quotes:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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;s1&quot;&gt;&#x27;A single-line string in single quotes&#x27;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;A single-line string in single quotes&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A single-line string in double quotes&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;A single-line string in double quotes&#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.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the first example, you use single quotes to delimit the string literal. In the second example, you use double quotes.&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; Python’s standard &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;REPL&lt;/a&gt; displays string objects using single quotes even though you create them using double quotes.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You can define empty strings using quotes without placing characters between them:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&#x27;&#x27;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;0&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.1440a154cfa8.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.1440a154cfa8.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;An empty string doesn’t contain any characters, so when you use the built-in &lt;a href=&quot;https://realpython.com/len-python-function/&quot;&gt;&lt;code&gt;len()&lt;/code&gt;&lt;/a&gt; function with an empty string as an argument, you get &lt;code&gt;0&lt;/code&gt; as a result.&lt;/p&gt;
&lt;p&gt;To create multiline strings, you can use triple-quoted strings. In this case, you can use either single or double quotes:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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;sd&quot;&gt;&#x27;&#x27;&#x27;A triple-quoted string&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;spanning across multiple&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;lines using single quotes&#x27;&#x27;&#x27;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;A triple-quoted string\nspanning across multiple\nlines using single quotes&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&quot;&quot;&quot;A triple-quoted string&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;spanning across multiple&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;lines using double quotes&quot;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;A triple-quoted string\nspanning across multiple\nlines using double quotes&#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.1440a154cfa8.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.1440a154cfa8.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 primary use case for triple-quoted strings is to create multiline strings. You can also use them to define single-line strings, but this is a less common practice.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-strings/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-strings/ »&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 #214: Build Captivating Display Tables in Python With Great Tables</title>
      <id>https://realpython.com/podcasts/rpp/214/</id>
      <link href="https://realpython.com/podcasts/rpp/214/"/>
      <updated>2024-07-26T12:00:00+00:00</updated>
      <summary>Do you need help making data tables in Python look interesting and attractive? How can you create beautiful display-ready tables as easily as charts and graphs in Python? This week on the show, we speak with Richard Iannone and Michael Chow from Posit about the Great Tables Python library.</summary>
      <content type="html">
        &lt;p&gt;Do you need help making data tables in Python look interesting and attractive? How can you create beautiful display-ready tables as easily as charts and graphs in Python? This week on the show, we speak with Richard Iannone and Michael Chow from Posit about the Great Tables Python 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 Basics: Lists and Tuples</title>
      <id>https://realpython.com/quizzes/python-basics-lists-and-tuples/</id>
      <link href="https://realpython.com/quizzes/python-basics-lists-and-tuples/"/>
      <updated>2024-07-25T12:00:00+00:00</updated>
      <summary>Lists and tuples are important sequence data structures in Python. Lists are mutable, while tuples are immutable. Combining your knowledge of control flow and loops with these sequences allows you to build complex logic.</summary>
      <content type="html">
        &lt;p&gt;In &lt;a href=&quot;https://realpython.com/courses/python-basics-lists-tuples/&quot;&gt;Python Basics: Lists and Tuples&lt;/a&gt;, you&amp;rsquo;ve met two new and important data structures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lists&lt;/li&gt;
&lt;li&gt;Tuples&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both of these data types are &lt;a href=&quot;https://realpython.com/python-sequences/&quot;&gt;sequences&lt;/a&gt;, meaning they are objects that contain other objects in a certain order. They each have some important distinguishing properties and come with their own set of methods for interacting with objects of each type.&lt;/p&gt;
&lt;p&gt;In this quiz, youll test your knowledge of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Creating&lt;/strong&gt; lists and tuples&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Indexing&lt;/strong&gt; and &lt;strong&gt;slicing&lt;/strong&gt; lists and tuples&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Iterating over&lt;/strong&gt; these containers&lt;/li&gt;
&lt;li&gt;Understanding their differences, specifically the impact of &lt;strong&gt;mutability&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Adding&lt;/strong&gt; and &lt;strong&gt;removing&lt;/strong&gt; items from a list&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then, you can move on to other &lt;a href=&quot;https://realpython.com/learning-paths/python-basics/&quot;&gt;Python Basics courses&lt;/a&gt;.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Getting Started With Testing in Python</title>
      <id>https://realpython.com/quizzes/testing-python/</id>
      <link href="https://realpython.com/quizzes/testing-python/"/>
      <updated>2024-07-25T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python testing. 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 &lt;a href=&quot;https://realpython.com/python-testing/&quot;&gt;testing your Python code&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 get started creating simple tests for your application in a few easy steps and then build on it from there.&lt;/p&gt;
&lt;p&gt;With this quiz, you can check your understanding of the fundamentals of Python testing. 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>Hugging Face Transformers: Leverage Open-Source AI in Python</title>
      <id>https://realpython.com/huggingface-transformers/</id>
      <link href="https://realpython.com/huggingface-transformers/"/>
      <updated>2024-07-24T14:00:00+00:00</updated>
      <summary>As the AI boom continues, the Hugging Face platform stands out as the leading open-source model hub. In this tutorial, you&#x27;ll get hands-on experience with Hugging Face and the Transformers library in Python.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Transformers is a powerful Python library created by Hugging Face that allows you to download, manipulate, and run thousands of pretrained, open-source AI models. These models cover multiple tasks across modalities like natural language processing, computer vision, audio, and multimodal learning. Using pretrained open-source models can reduce costs, save the time needed to train models from scratch, and give you more control over the models you deploy.&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;Navigate&lt;/strong&gt; the Hugging Face ecosystem&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Download, run, and manipulate&lt;/strong&gt; models with Transformers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Speed up&lt;/strong&gt; model inference with GPUs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Throughout this tutorial, you’ll gain a conceptual understanding of Hugging Face’s AI offerings and learn how to work with the Transformers library through hands-on examples. When you finish, you’ll have the knowledge and tools you need to start using models for your own use cases. Before starting, you’ll benefit from having an intermediate understanding of Python and popular deep learning libraries like &lt;a href=&quot;https://realpython.com/pytorch-vs-tensorflow/&quot;&gt;&lt;code&gt;pytorch&lt;/code&gt; and &lt;code&gt;tensorflow&lt;/code&gt;&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/huggingface-transformers-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-huggingface-transformers-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 Hugging Face Transformers to leverage open-source AI 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.1440a154cfa8.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 “Hugging Face Transformers” 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/hugging-face-transformers/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #abe0e6;&quot; alt=&quot;Hugging Face Transformers: Leverage Open-Source AI in Python&quot; src=&quot;https://files.realpython.com/media/Showcase-HuggingFace-Transformers_Watermarked-3.bfafcf75db45.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Showcase-HuggingFace-Transformers_Watermarked-3.bfafcf75db45.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Showcase-HuggingFace-Transformers_Watermarked-3.bfafcf75db45.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Showcase-HuggingFace-Transformers_Watermarked-3.bfafcf75db45.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Showcase-HuggingFace-Transformers_Watermarked-3.bfafcf75db45.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.1440a154cfa8.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/hugging-face-transformers/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Hugging Face Transformers&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 Hugging Face Transformers library. This library is a popular choice for working with transformer models in natural language processing tasks, computer vision, and other machine learning applications.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;the-hugging-face-ecosystem&quot;&gt;The Hugging Face Ecosystem&lt;a class=&quot;headerlink&quot; href=&quot;#the-hugging-face-ecosystem&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before using Transformers, you’ll want to have a solid understanding of the Hugging Face ecosystem. In this first section, you’ll briefly explore everything that Hugging Face offers with a particular emphasis on &lt;strong&gt;model cards&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;exploring-hugging-face&quot;&gt;Exploring Hugging Face&lt;a class=&quot;headerlink&quot; href=&quot;#exploring-hugging-face&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://huggingface.co/&quot;&gt;Hugging Face&lt;/a&gt; is a hub for state-of-the-art AI models. It’s primarily known for its wide range of open-source transformer-based models that excel in natural language processing (NLP), computer vision, and audio tasks. The platform offers several resources and services that cater to developers, researchers, businesses, and anyone interested in exploring AI models for their own use cases. &lt;/p&gt;
&lt;p&gt;There’s a lot you can do with Hugging Face, but the primary offerings can be broken down into a few categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt;: Hugging Face hosts a vast repository of pretrained AI models that are readily accessible and highly customizable. This repository is called the Model Hub, and it hosts models covering a wide range of tasks, including text classification, text generation, translation, summarization, speech recognition, image classification, and more. The platform is community-driven and allows users to contribute their own models, which facilitates a diverse and ever-growing selection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Datasets&lt;/strong&gt;: Hugging Face has a library of thousands of datasets that you can use to train, benchmark, and enhance your models. These range from small-scale benchmarks to massive, real-world datasets that encompass a variety of domains, such as text, image, and audio data. Like the Model Hub, 🤗 Datasets supports community contributions and provides the tools you need to search, download, and use data in your machine learning projects. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Spaces&lt;/strong&gt;: Spaces allows you to deploy and share machine learning applications directly on the Hugging Face website. This service supports a variety of frameworks and interfaces, including Streamlit, Gradio, and Jupyter notebooks. It is particularly useful for showcasing model capabilities, hosting interactive demos, or for educational purposes, as it allows you to interact with models in real time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Paid offerings&lt;/strong&gt;: Hugging Face also offers several &lt;a href=&quot;https://huggingface.co/pricing&quot;&gt;paid services&lt;/a&gt; for enterprises and advanced users. These include the Pro Account, the Enterprise Hub, and Inference Endpoints. These solutions offer private model hosting, advanced collaboration tools, and dedicated support to help organizations scale their AI operations effectively.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These resources empower you to accelerate your AI projects and encourage collaboration and innovation within the community. Whether you’re a novice looking to experiment with pretrained models, or an enterprise seeking robust AI solutions, Hugging Face offers tools and platforms that cater to a wide range of needs.&lt;/p&gt;
&lt;p&gt;This tutorial focuses on Transformers, a Python library that lets you run just about any model in the Model Hub. Before using &lt;code&gt;transformers&lt;/code&gt;, you’ll need to understand what model cards are, and that’s what you’ll do next.&lt;/p&gt;
&lt;h3 id=&quot;understanding-model-cards&quot;&gt;Understanding Model Cards&lt;a class=&quot;headerlink&quot; href=&quot;#understanding-model-cards&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://huggingface.co/docs/hub/en/model-cards&quot;&gt;Model cards&lt;/a&gt; are the core components of the Model Hub, and you’ll need to understand how to search and read them to use models in Transformers. Model cards are nothing more than files that accompany each model to provide useful information. You can search for the model card you’re looking for on the Models page:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/Screenshot_2024-05-25_at_2.50.35_PM.272112bd8bb6.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/Screenshot_2024-05-25_at_2.50.35_PM.272112bd8bb6.png&quot; width=&quot;3370&quot; height=&quot;1936&quot; srcset=&quot;/cdn-cgi/image/width=842,format=auto/https://files.realpython.com/media/Screenshot_2024-05-25_at_2.50.35_PM.272112bd8bb6.png 842w, /cdn-cgi/image/width=1123,format=auto/https://files.realpython.com/media/Screenshot_2024-05-25_at_2.50.35_PM.272112bd8bb6.png 1123w, /cdn-cgi/image/width=1685,format=auto/https://files.realpython.com/media/Screenshot_2024-05-25_at_2.50.35_PM.272112bd8bb6.png 1685w, /cdn-cgi/image/width=3370,format=auto/https://files.realpython.com/media/Screenshot_2024-05-25_at_2.50.35_PM.272112bd8bb6.png 3370w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;HuggingFace Models page&quot; data-asset=&quot;5814&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Hugging Face Models page&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;On the left side of the Models page, you can search for model cards based on the task you’re interested in. For example, if you’re interested in &lt;a href=&quot;https://huggingface.co/tasks/zero-shot-classification&quot;&gt;zero-shot text classification&lt;/a&gt;, you can click the &lt;code&gt;Zero-Shot Classification&lt;/code&gt; button under the &lt;code&gt;Natural Language Processing&lt;/code&gt; section:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/Screenshot_2024-05-26_at_1.16.02_PM.eecd94e4a2d0.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/Screenshot_2024-05-26_at_1.16.02_PM.eecd94e4a2d0.png&quot; width=&quot;3074&quot; height=&quot;1666&quot; srcset=&quot;/cdn-cgi/image/width=768,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.16.02_PM.eecd94e4a2d0.png 768w, /cdn-cgi/image/width=1024,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.16.02_PM.eecd94e4a2d0.png 1024w, /cdn-cgi/image/width=1537,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.16.02_PM.eecd94e4a2d0.png 1537w, /cdn-cgi/image/width=3074,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.16.02_PM.eecd94e4a2d0.png 3074w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;HuggingFace Models page filtered to zero-shot text classification&quot; data-asset=&quot;5815&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Hugging Face Models page filtered for zero-shot text classification models&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;In this search, you can see 266 different zero-shot text classification models, which is a paradigm where language models assign labels to text without explicit training or seeing any examples. In the upper-right corner, you can sort the search results based on model likes, downloads, creation dates, updated dates, and popularity trends. &lt;/p&gt;
&lt;p&gt;Each model card button tells you the model’s task, when it was last updated, and how many downloads and likes it has. When you click a model card button, say the one for the &lt;a href=&quot;https://huggingface.co/facebook/bart-large-mnli&quot;&gt;&lt;code&gt;facebook/bart-large-mnli&lt;/code&gt;&lt;/a&gt; model, the model card will open and display all of the model’s information:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/Screenshot_2024-05-26_at_1.36.57_PM.87c9cde69339.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/Screenshot_2024-05-26_at_1.36.57_PM.87c9cde69339.png&quot; width=&quot;3448&quot; height=&quot;1944&quot; srcset=&quot;/cdn-cgi/image/width=862,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.36.57_PM.87c9cde69339.png 862w, /cdn-cgi/image/width=1149,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.36.57_PM.87c9cde69339.png 1149w, /cdn-cgi/image/width=1724,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.36.57_PM.87c9cde69339.png 1724w, /cdn-cgi/image/width=3448,format=auto/https://files.realpython.com/media/Screenshot_2024-05-26_at_1.36.57_PM.87c9cde69339.png 3448w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;HuggingFace model card&quot; data-asset=&quot;5816&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;A Hugging Face model card&lt;/figcaption&gt;&lt;/figure&gt;

&lt;p&gt;Even though a model card can display just about anything, Hugging Face has &lt;a href=&quot;https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md&quot;&gt;outlined&lt;/a&gt; the information that a good model card should provide. This includes detailed information about the model, its uses and limitations, the training parameters and experiment details, the dataset used to train the model, and the model’s evaluation performance.&lt;/p&gt;
&lt;p&gt;A high-quality model card also includes metadata such as the model’s license, references to the training data, and links to research papers that describe the model in detail. In some model cards, you’ll also get to tinker with a deployed instance of the model via the &lt;a href=&quot;https://huggingface.co/inference-api/serverless&quot;&gt;Inference API&lt;/a&gt;. You can see an example of this in the &lt;code&gt;facebook/bart-large-mnli&lt;/code&gt; model card:&lt;/p&gt;
&lt;figure class=&quot;js-lightbox&quot;&gt;&lt;a href=&quot;https://files.realpython.com/media/Screenshot_2024-05-27_at_10.34.39_PM.3e20bb8f558a.png&quot; target=&quot;_blank&quot;&gt;&lt;img loading=&quot;lazy&quot; class=&quot;img-fluid mx-auto d-block &quot; src=&quot;https://files.realpython.com/media/Screenshot_2024-05-27_at_10.34.39_PM.3e20bb8f558a.png&quot; width=&quot;1822&quot; height=&quot;1106&quot; srcset=&quot;/cdn-cgi/image/width=455,format=auto/https://files.realpython.com/media/Screenshot_2024-05-27_at_10.34.39_PM.3e20bb8f558a.png 455w, /cdn-cgi/image/width=607,format=auto/https://files.realpython.com/media/Screenshot_2024-05-27_at_10.34.39_PM.3e20bb8f558a.png 607w, /cdn-cgi/image/width=911,format=auto/https://files.realpython.com/media/Screenshot_2024-05-27_at_10.34.39_PM.3e20bb8f558a.png 911w, /cdn-cgi/image/width=1822,format=auto/https://files.realpython.com/media/Screenshot_2024-05-27_at_10.34.39_PM.3e20bb8f558a.png 1822w&quot; sizes=&quot;(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)&quot; alt=&quot;HuggingFace Inference API within A model card&quot; data-asset=&quot;5818&quot;&gt;&lt;/a&gt;&lt;figcaption class=&quot;figure-caption text-center&quot;&gt;Tinker with Hugging Face models using the Inference API&lt;/figcaption&gt;&lt;/figure&gt;

&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/huggingface-transformers/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/huggingface-transformers/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python Protocols: Leveraging Structural Subtyping</title>
      <id>https://realpython.com/quizzes/python-protocol/</id>
      <link href="https://realpython.com/quizzes/python-protocol/"/>
      <updated>2024-07-24T12:00:00+00:00</updated>
      <summary>Take this quiz to test your understanding of how to create and use Python protocols while providing type hints for your functions, variables, classes, and methods.</summary>
      <content type="html">
        &lt;p&gt;Test your understanding of how to create and use Python protocols while providing type hints for your functions, variables, classes, and methods.&lt;/p&gt;
&lt;p&gt;Take this quiz after reading our &lt;a href=&quot;https://realpython.com/python-protocol/&quot;&gt;Python Protocols: Leveraging Structural Subtyping&lt;/a&gt; tutorial.&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: Hugging Face Transformers</title>
      <id>https://realpython.com/quizzes/hugging-face-transformers/</id>
      <link href="https://realpython.com/quizzes/hugging-face-transformers/"/>
      <updated>2024-07-24T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of the Hugging Face Transformers library. This library is a popular choice for working with transformer models in natural language processing tasks, computer vision, and other machine learning applications.</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/huggingface-transformers/&quot;&gt;Hugging Face Transformers&lt;/a&gt;. This library is a popular choice for working with transformer models in natural language processing tasks, computer vision, and other machine learning applications.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Logging in Python</title>
      <id>https://realpython.com/quizzes/logging-in-python/</id>
      <link href="https://realpython.com/quizzes/logging-in-python/"/>
      <updated>2024-07-24T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s logging module. With this knowledge, you&#x27;ll be able to add logging to your applications, which can help you debug errors and analyze performance.</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-logging/&quot;&gt;Python&amp;rsquo;s &lt;code&gt;logging&lt;/code&gt; module&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Logging is a very useful tool in a programmer&amp;rsquo;s toolbox. It can help you develop a better understanding of the flow of a program and discover scenarios that you might not have thought of while developing.&lt;/p&gt;
&lt;p&gt;Logs provide developers with an extra set of eyes that are constantly looking at the flow an application is going through.&lt;/p&gt;
&lt;p&gt;They can store information, like which user or IP accessed the application. If an error occurs, then they can provide more insights than a stack trace by telling you what the state of the program was before it arrived and the line of code where the error occurred.&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>pandas GroupBy: Grouping Real World Data in Python</title>
      <id>https://realpython.com/courses/pandas-groupby-real-world-data/</id>
      <link href="https://realpython.com/courses/pandas-groupby-real-world-data/"/>
      <updated>2024-07-23T14:00:00+00:00</updated>
      <summary>In this course, you&#x27;ll learn how to work adeptly with the pandas GroupBy while mastering ways to manipulate, transform, and summarize data. You&#x27;ll work with real-world datasets and chain GroupBy methods together to get data into an output that suits your needs.</summary>
      <content type="html">
        &lt;p&gt;Whether you&amp;rsquo;ve just started working with &lt;a href=&quot;https://realpython.com/pandas-python-explore-dataset/&quot;&gt;pandas&lt;/a&gt; and want to master one of its core capabilities, or you&amp;rsquo;re looking to fill in some gaps in your understanding about &lt;code&gt;.groupby()&lt;/code&gt;, this course will help you to break down and visualize a &lt;strong&gt;pandas GroupBy&lt;/strong&gt; operation from start to finish.&lt;/p&gt;
&lt;p&gt;This course is meant to complement the &lt;a href=&quot;https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html&quot;&gt;official pandas documentation&lt;/a&gt; and the &lt;a href=&quot;https://pandas.pydata.org/pandas-docs/stable/user_guide/cookbook.html#cookbook-grouping&quot;&gt;pandas Cookbook&lt;/a&gt;, where there are self-contained, bite-sized examples. Here, however, you&amp;rsquo;ll focus on three more involved walkthroughs that use real-world datasets.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this course, you&amp;rsquo;ll cover:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to use pandas &lt;strong&gt;GroupBy operations&lt;/strong&gt; on &lt;strong&gt;real-world data&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How the &lt;strong&gt;split-apply-combine&lt;/strong&gt; chain of operations works&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;decompose&lt;/strong&gt; the split-apply-combine chain into steps&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;categorize methods&lt;/strong&gt; of a pandas GroupBy object based on their intent and result&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>Logging in Python</title>
      <id>https://realpython.com/python-logging/</id>
      <link href="https://realpython.com/python-logging/"/>
      <updated>2024-07-22T14:00:00+00:00</updated>
      <summary>If you use Python&#x27;s print() function to get information about the flow of your programs, then logging is the natural next step for you. This tutorial will guide you through creating your first logs and show you ways to curate them to grow with your projects.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Recording relevant information during the execution of your program is a good practice as a Python developer when you want to gain a better understanding of your code. This practice is called &lt;strong&gt;logging&lt;/strong&gt;, and it’s a very useful tool for your programmer’s toolbox. It can help you discover scenarios that you might not have thought of while developing.&lt;/p&gt;
&lt;p&gt;These records are called &lt;strong&gt;logs&lt;/strong&gt;, and they can serve as an extra set of eyes that are constantly looking at your application’s flow. Logs can store information, like which user or IP accessed the application. If an error occurs, then logs may provide more insights than a stack trace by telling you the state of the program before the error and the line of code where it occurred.&lt;/p&gt;
&lt;p&gt;Python provides a logging system as part of its standard library. You can add logging to your application with just a few lines of 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 Python’s &lt;strong&gt;&lt;code&gt;logging&lt;/code&gt; module&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Set up a &lt;strong&gt;basic logging configuration&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Leverage &lt;strong&gt;log levels&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Style your log messages with &lt;strong&gt;formatters&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Redirect log records with &lt;strong&gt;handlers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Define logging rules with &lt;strong&gt;filters&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you log useful data from the right places, you can debug errors, analyze the application’s performance to plan for scaling, or look at usage patterns to plan for marketing.&lt;/p&gt;
&lt;p&gt;You’ll do the coding for this tutorial in the &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python standard REPL&lt;/a&gt;. If you prefer Python files, then you’ll find a full logging example as a script in the materials of this tutorial. You can download this script 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/python-logging-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-logging-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that you’ll use to learn about logging 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.1440a154cfa8.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 “Logging 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/logging-in-python/&quot; tabindex=&quot;-1&quot;&gt;
        &lt;div class=&quot;embed-responsive embed-responsive-16by9&quot;&gt;

            &lt;img class=&quot;card-img-top m-0 p-0 embed-responsive-item rounded&quot; style=&quot;object-fit: contain; background: #e6c7ab;&quot; alt=&quot;Logging in Python&quot; src=&quot;https://files.realpython.com/media/Logging-in-Python_Watermarked.4ca8974dc55c.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Logging-in-Python_Watermarked.4ca8974dc55c.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Logging-in-Python_Watermarked.4ca8974dc55c.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Logging-in-Python_Watermarked.4ca8974dc55c.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Logging-in-Python_Watermarked.4ca8974dc55c.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.1440a154cfa8.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/logging-in-python/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Logging in Python&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;In this quiz, you&#x27;ll test your understanding of Python&#x27;s logging module. With this knowledge, you&#x27;ll be able to add logging to your applications, which can help you debug errors and analyze performance.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;If you commonly use Python’s &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt; function to get information about the flow of your programs, then logging is the natural next step for you. This tutorial will guide you through creating your first logs and show you how to make logging grow with your projects.&lt;/p&gt;
&lt;h2 id=&quot;starting-with-pythons-logging-module&quot;&gt;Starting With Python’s Logging Module&lt;a class=&quot;headerlink&quot; href=&quot;#starting-with-pythons-logging-module&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://docs.python.org/3/library/logging.html#module-logging/&quot;&gt;&lt;code&gt;logging&lt;/code&gt; module&lt;/a&gt; in Python’s standard library is a ready-to-use, powerful module that’s designed to meet the needs of beginners as well as enterprise teams.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Since logs offer a variety of insights, the &lt;code&gt;logging&lt;/code&gt; module is often used by other third-party Python libraries, too. Once you’re more advanced in the practice of logging, you can integrate your log messages with the ones from those libraries to produce a homogeneous log for your application.&lt;/p&gt;
&lt;p&gt;To leverage this versatility, it’s a good idea to get a better understanding of how the &lt;code&gt;logging&lt;/code&gt; module works under the hood. For example, you could take &lt;a href=&quot;https://realpython.com/python-logging-source-code/&quot;&gt;a stroll through the &lt;code&gt;logging&lt;/code&gt; module’s source code&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The main component of the &lt;code&gt;logging&lt;/code&gt; module is something called the &lt;strong&gt;logger&lt;/strong&gt;. You can think of the logger as a reporter in your code that decides what to record, at what level of detail, and where to store or send these records.&lt;/p&gt;
&lt;h3 id=&quot;exploring-the-root-logger&quot;&gt;Exploring the Root Logger&lt;a class=&quot;headerlink&quot; href=&quot;#exploring-the-root-logger&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To get a first impression of how the &lt;code&gt;logging&lt;/code&gt; module and a logger work, open the &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;Python standard REPL&lt;/a&gt; and enter the code below:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.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;logging&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;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Remain calm!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;WARNING:root:Remain calm!&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.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The output shows the severity level before each message along with &lt;code&gt;root&lt;/code&gt;, which is the name the &lt;code&gt;logging&lt;/code&gt; module gives to its default logger. This output shows the default format that can be configured to include things like a timestamp or other details.&lt;/p&gt;
&lt;p&gt;In the example above, you’re sending a message on the &lt;code&gt;root&lt;/code&gt; logger. The &lt;strong&gt;log level&lt;/strong&gt; of the message is &lt;code&gt;WARNING&lt;/code&gt;. Log levels are an important aspect of logging. By default, there are five standard levels indicating the severity of events. Each has a corresponding function that can be used to log events at that level of severity. &lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; There’s also a &lt;code&gt;NOTSET&lt;/code&gt; log level, which you’ll encounter later in this tutorial when you learn about custom logging handlers.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Here are the five default log levels, in order of increasing severity:&lt;/p&gt;
&lt;div class=&quot;table-responsive&quot;&gt;
&lt;table class=&quot;table table-hover&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Log Level&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DEBUG&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;logging.debug()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Provides detailed information that’s valuable to you as a developer.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;INFO&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;logging.info()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Provides general information about what’s going on with your program.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;WARNING&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;logging.warning()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Indicates that there’s something you should look into.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ERROR&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;logging.error()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Alerts you to an unexpected problem that’s occured in your program.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CRITICAL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;logging.critical()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tells you that a serious error has occurred and may have crashed your app.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;logging&lt;/code&gt; module provides you with a default logger that allows you to get started with logging without needing to do much configuration. However, the &lt;code&gt;logging&lt;/code&gt; functions listed in the table above reveal a quirk that you may not expect:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This is a debug message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This is an info message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This is a warning message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;WARNING:root:This is a warning message&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;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This is an error message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;ERROR:root:This is an error message&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;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;critical&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;This is a critical message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;CRITICAL:root:This is a critical message&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.1440a154cfa8.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.1440a154cfa8.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;Notice that the &lt;code&gt;debug()&lt;/code&gt; and &lt;code&gt;info()&lt;/code&gt; messages didn’t get logged. This is because, by default, the logging module logs the messages with a severity level of &lt;code&gt;WARNING&lt;/code&gt; or above. You can change that by configuring the logging module to log events of all levels. &lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-logging/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-logging/ »&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 #213: Constraint Programming &amp; Exploring Python&#x27;s Built-in Functions</title>
      <id>https://realpython.com/podcasts/rpp/213/</id>
      <link href="https://realpython.com/podcasts/rpp/213/"/>
      <updated>2024-07-19T12:00:00+00:00</updated>
      <summary>What are discrete optimization problems? How do you solve them with constraint programming in Python? 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 discrete optimization problems? How do you solve them with constraint programming in Python? 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 Protocols: Leveraging Structural Subtyping</title>
      <id>https://realpython.com/python-protocol/</id>
      <link href="https://realpython.com/python-protocol/"/>
      <updated>2024-07-17T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about Python&#x27;s protocols and how they can help you get the most out of using Python&#x27;s type hint system and static type checkers.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In Python, a &lt;strong&gt;protocol&lt;/strong&gt; specifies the methods and attributes that a class must implement to be considered of a given type. Protocols are important in Python’s &lt;strong&gt;type hint system&lt;/strong&gt;, which allows for static type checking through external tools, such as &lt;a href=&quot;http://mypy-lang.org/&quot;&gt;mypy&lt;/a&gt;, &lt;a href=&quot;https://github.com/microsoft/pyright&quot;&gt;Pyright&lt;/a&gt;, and &lt;a href=&quot;https://pyre-check.org/&quot;&gt;Pyre&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Before there were protocols, these tools could only check for &lt;strong&gt;nominal subtyping&lt;/strong&gt; based on inheritance. There was no way to check for &lt;strong&gt;structural subtyping&lt;/strong&gt;, which relies on the internal structure of classes. This limitation affected Python’s &lt;strong&gt;duck typing&lt;/strong&gt; system, which allows you to use objects without considering their nominal types. Protocols overcome this limitation, making static duck typing possible.&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;Gain clarity around the use of the term &lt;strong&gt;protocol&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;Learn how &lt;strong&gt;type hints&lt;/strong&gt; facilitate &lt;strong&gt;static type checking&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Learn how protocols allow &lt;strong&gt;static duck typing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Create custom protocols with the &lt;strong&gt;&lt;code&gt;Protocol&lt;/code&gt; class&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Understand the differences between &lt;strong&gt;protocols&lt;/strong&gt; and &lt;strong&gt;abstract base classes&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you’ll need to know the basics of &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt; in Python, including concepts such as &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;inheritance&lt;/a&gt;. You should also know about &lt;a href=&quot;https://realpython.com/python-type-checking/&quot;&gt;type checking&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/duck-typing-python/&quot;&gt;duck typing&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/python-protocol-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-protocol-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 leverage structural subtyping with Python protocols&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.1440a154cfa8.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 Protocols: Leveraging Structural Subtyping” 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-protocol/&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: #aae4b1;&quot; alt=&quot;Python Protocols: Leveraging Structural Subtyping&quot; src=&quot;https://files.realpython.com/media/Python-Protocols-How-to-Leverage-Their-Power_Watermarked.a24776f88b49.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-Protocols-How-to-Leverage-Their-Power_Watermarked.a24776f88b49.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-Protocols-How-to-Leverage-Their-Power_Watermarked.a24776f88b49.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-Protocols-How-to-Leverage-Their-Power_Watermarked.a24776f88b49.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-Protocols-How-to-Leverage-Their-Power_Watermarked.a24776f88b49.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.1440a154cfa8.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-protocol/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python Protocols: Leveraging Structural Subtyping&lt;/span&gt;&lt;/a&gt; 
      &lt;p class=&quot;text-muted mb-0 small&quot;&gt;Take this quiz to test your understanding of how to create and use Python protocols while providing type hints for your functions, variables, classes, and methods.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;the-meaning-of-protocol-in-python&quot;&gt;The Meaning of “Protocol” in Python&lt;a class=&quot;headerlink&quot; href=&quot;#the-meaning-of-protocol-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;During Python’s evolution, the term &lt;strong&gt;protocol&lt;/strong&gt; became overloaded with two subtly different meanings. The first meaning refers to internal protocols, such as the &lt;a href=&quot;https://realpython.com/python-iterators-iterables/#what-is-the-python-iterator-protocol&quot;&gt;iterator&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-with-statement/#creating-custom-context-managers&quot;&gt;context manager&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-descriptors/&quot;&gt;descriptor&lt;/a&gt; protocols.&lt;/p&gt;
&lt;p&gt;These protocols are widely understood in the community and consist of &lt;a href=&quot;https://realpython.com/python-magic-methods/&quot;&gt;special methods&lt;/a&gt; that make up a given protocol. For example, the &lt;a href=&quot;https://docs.python.org/3/library/stdtypes.html#iterator.__iter__&quot;&gt;&lt;code&gt;.__iter__()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/3/library/stdtypes.html#iterator.__next__&quot;&gt;&lt;code&gt;.__next__()&lt;/code&gt;&lt;/a&gt; methods define the iterator protocol.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://realpython.com/python38-new-features/&quot;&gt;Python 3.8&lt;/a&gt; introduced a second, slightly different type of &lt;a href=&quot;https://realpython.com/python38-new-features/#more-precise-types&quot;&gt;protocol&lt;/a&gt;. These protocols specify the methods and attributes that a class must implement to be considered of a given type. So, these protocols also have to do with a class’s internal structure.&lt;/p&gt;
&lt;p&gt;With this kind of protocol, you can define interchangeable classes as long as they share a common internal structure. This feature allows you to enforce a relationship between types or classes without the burden of &lt;a href=&quot;https://realpython.com/inheritance-composition-python/#whats-inheritance&quot;&gt;inheritance&lt;/a&gt;. This relationship is known as &lt;strong&gt;structural subtyping&lt;/strong&gt; or &lt;a href=&quot;https://realpython.com/duck-typing-python/#understanding-type-hints-and-static-duck-typing&quot;&gt;static duck typing&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this tutorial, you’ll focus on this second meaning of the term protocol. First, you’ll have a look at how Python manages types.&lt;/p&gt;
&lt;h2 id=&quot;dynamic-and-static-typing-in-python&quot;&gt;Dynamic and Static Typing in Python&lt;a class=&quot;headerlink&quot; href=&quot;#dynamic-and-static-typing-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python is a dynamically typed language, which means that the Python interpreter checks an object’s type when the code runs. It also means that while a variable can only reference one object at a time, the type of that object can change during the variable’s lifetime.&lt;/p&gt;
&lt;p&gt;For example, you can have a variable that starts as a string and changes into an integer number:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;One hundred&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;One hundred&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;100&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.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you have a variable that starts as a string. Later in your code, you change the variable’s value to an integer.&lt;/p&gt;
&lt;p&gt;Because of its dynamic nature, Python has embraced a flexible typing system that’s known as duck typing.&lt;/p&gt;
&lt;h3 id=&quot;duck-typing&quot;&gt;Duck Typing&lt;a class=&quot;headerlink&quot; href=&quot;#duck-typing&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Duck typing is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Type_system&quot;&gt;type system&lt;/a&gt; in which an object is considered compatible with a given type if it has all the &lt;a href=&quot;https://realpython.com/python-classes/#providing-behavior-with-methods&quot;&gt;methods&lt;/a&gt; and &lt;a href=&quot;https://realpython.com/python-classes/#attaching-data-to-classes-and-instances&quot;&gt;attributes&lt;/a&gt; that the type requires. This typing system supports the ability to use objects of independent and decoupled classes in a specific context as long as they adhere to some common interface.&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 duck typing, check out the &lt;a href=&quot;https://realpython.com/duck-typing-python/&quot;&gt;Duck Typing in Python: Writing Flexible and Decoupled Code&lt;/a&gt; tutorial.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As an example of duck typing, you can consider built-in container data types, such as &lt;a href=&quot;https://realpython.com/python-list/&quot;&gt;lists&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-tuple/&quot;&gt;tuples&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;strings&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-dicts/&quot;&gt;dictionaries&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-sets/&quot;&gt;sets&lt;/a&gt;. All of these data types support iteration:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; role=&quot;button&quot;&gt;&lt;span class=&quot;icon baseline js-codeblock-output-on codeblock__header--icon-lower&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.1440a154cfa8.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;person&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Jane&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Python Dev&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;letters&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;abc&quot;&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ordinals&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;first&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;two&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;second&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;three&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;third&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;even_digits&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;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;containers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;letters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ordinals&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;even_digits&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;container&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;containers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;1 2 3 &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Jane 25 Python Dev &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;a b c &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;one two three &lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;8 2 4 6 &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.1440a154cfa8.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.1440a154cfa8.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this code snippet, you define a few variables using different built-in types. Then, you start a &lt;a href=&quot;https://realpython.com/python-for-loop/&quot;&gt;&lt;code&gt;for&lt;/code&gt;&lt;/a&gt; loop over the collections and iterate over each of them to print their elements to the screen. Even though the built-in types are significantly different from one another, they all support iteration.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-protocol/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-protocol/ »&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>Exercises Course: Introduction to Web Scraping With Python</title>
      <id>https://realpython.com/courses/exercises-introduction-web-scraping/</id>
      <link href="https://realpython.com/courses/exercises-introduction-web-scraping/"/>
      <updated>2024-07-16T14:00:00+00:00</updated>
      <summary>In this course, you&#x27;ll practice the main steps of the web scraping process. You&#x27;ll write a script that uses Python&#x27;s requests library to scrape and parse data from a website. You&#x27;ll also interact with HTML forms using tools like Beautiful Soup and Mechanical Soup to extract specific information.</summary>
      <content type="html">
        &lt;p&gt;&lt;strong&gt;Web scraping&lt;/strong&gt; is the process of collecting and parsing raw data from the Web, and the Python community has come up with some pretty powerful web scraping tools.&lt;/p&gt;
&lt;p&gt;The Internet hosts the greatest source of information on the planet. Many disciplines, such as &lt;a href=&quot;https://realpython.com/learning-paths/data-science-python-core-skills/&quot;&gt;data science&lt;/a&gt;, business intelligence, and investigative reporting, can benefit enormously from collecting and analyzing data from websites. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this course, you&amp;rsquo;ll practice:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Parsing website data using &lt;strong&gt;string methods&lt;/strong&gt; and &lt;strong&gt;regular expressions&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Parsing website data using an &lt;strong&gt;HTML parser&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Interacting with &lt;strong&gt;forms&lt;/strong&gt; and other website components&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 #212: Digging Into Graph Theory in Python With David Amos</title>
      <id>https://realpython.com/podcasts/rpp/212/</id>
      <link href="https://realpython.com/podcasts/rpp/212/"/>
      <updated>2024-07-12T12:00:00+00:00</updated>
      <summary>Have you wondered about graph theory and how to start exploring it in Python? What resources and Python libraries can you use to experiment and learn more? This week on the show, former co-host David Amos returns to talk about what he&#x27;s been up to and share his knowledge about graph theory in Python.</summary>
      <content type="html">
        &lt;p&gt;Have you wondered about graph theory and how to start exploring it in Python? What resources and Python libraries can you use to experiment and learn more? This week on the show, former co-host David Amos returns to talk about what he&#x27;s been up to and share his knowledge about graph theory in Python.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Customize VS Code Settings</title>
      <id>https://realpython.com/courses/customize-vscode-settings/</id>
      <link href="https://realpython.com/courses/customize-vscode-settings/"/>
      <updated>2024-07-09T14:00:00+00:00</updated>
      <summary>In this course, Philipp helps you customize your Visual Studio Code settings to switch from a basic cluttered look to a clean presentable look. This is not just pleasant on the eyes, but also gives you a nice user interface if you want to share on a zoom call or screen recording.</summary>
      <content type="html">
        &lt;p&gt;Visual Studio Code, is an open-source code editor available on all platforms. It’s also a great platform for Python development. The default settings in VS Code present a somewhat cluttered environment. &lt;/p&gt;
&lt;p&gt;This &lt;strong&gt;Code Conversation&lt;/strong&gt; with instructor Philipp Acsany is about learning how to customize the settings within the interface of VS Code. Having a clean digital workspace is an important part of your work life. Removing distractions and making code more readable can increase productivity and even help you spot bugs.&lt;/p&gt;
&lt;p&gt;In this &lt;strong&gt;Code Conversation&lt;/strong&gt;, you&amp;rsquo;ll learn how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Work With User Settings&lt;/li&gt;
&lt;li&gt;Create a VS Code Profile&lt;/li&gt;
&lt;li&gt;Find and Adjust Specific Settings&lt;/li&gt;
&lt;li&gt;Clean Up the VS Code User Interface&lt;/li&gt;
&lt;li&gt;Export Your Profile to Re-use Across Installations&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 #211: Python Doesn&#x27;t Round Numbers the Way You Might Think</title>
      <id>https://realpython.com/podcasts/rpp/211/</id>
      <link href="https://realpython.com/podcasts/rpp/211/"/>
      <updated>2024-07-05T12:00:00+00:00</updated>
      <summary>Does Python round numbers the same way you learned back in math class? You might be surprised by the default method Python uses and the variety of ways to round numbers in Python. 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;Does Python round numbers the same way you learned back in math class? You might be surprised by the default method Python uses and the variety of ways to round numbers in Python. Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Defining Python Constants for Code Maintainability</title>
      <id>https://realpython.com/courses/defining-constants-code-maintainability/</id>
      <link href="https://realpython.com/courses/defining-constants-code-maintainability/"/>
      <updated>2024-07-02T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to properly define constants in Python. By coding a bunch of practical example, you&#x27;ll also learn how Python constants can improve your code&#x27;s readability, reusability, and maintainability.</summary>
      <content type="html">
        &lt;p&gt;In programming, the term &lt;strong&gt;constant&lt;/strong&gt; refers to names representing values that don&amp;rsquo;t change during a program&amp;rsquo;s execution. Constants are a fundamental concept in programming, and Python developers use them in many cases. However, Python doesn&amp;rsquo;t have a dedicated syntax for defining constants. In practice, Python constants are just &lt;strong&gt;variables&lt;/strong&gt; that &lt;em&gt;never change&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;To prevent programmers from reassigning a name that&amp;rsquo;s supposed to hold a constant, the Python community has adopted a naming convention: &lt;em&gt;use uppercase letters&lt;/em&gt;. For every Pythonista, it&amp;rsquo;s essential to know what constants are, as well as why and when to use them.&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;Properly &lt;strong&gt;define constants&lt;/strong&gt; in Python&lt;/li&gt;
&lt;li&gt;Identify some &lt;strong&gt;built-in constants&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Use constants to improve your code&amp;rsquo;s &lt;strong&gt;readability&lt;/strong&gt;, &lt;strong&gt;reusability&lt;/strong&gt;, and &lt;strong&gt;maintainability&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Apply different approaches to &lt;strong&gt;organize&lt;/strong&gt; and &lt;strong&gt;manage&lt;/strong&gt; constants in a project&lt;/li&gt;
&lt;li&gt;Use several techniques to make constants &lt;strong&gt;strictly constant&lt;/strong&gt; in Python&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #210: Creating a Guitar Synthesizer &amp; Generating WAV Files With Python</title>
      <id>https://realpython.com/podcasts/rpp/210/</id>
      <link href="https://realpython.com/podcasts/rpp/210/"/>
      <updated>2024-06-28T12:00:00+00:00</updated>
      <summary>What techniques go into synthesizing a guitar sound in Python? What higher-level programming and Python concepts can you practice while building advanced projects? This week on the show, we talk with Real Python author and core team member Bartosz Zaczyński about his recent step-by-step project, Build a Guitar Synthesizer: Play Musical Tablature in Python.</summary>
      <content type="html">
        &lt;p&gt;What techniques go into synthesizing a guitar sound in Python? What higher-level programming and Python concepts can you practice while building advanced projects? This week on the show, we talk with Real Python author and core team member Bartosz Zaczyński about his recent step-by-step project, Build a Guitar Synthesizer: Play Musical Tablature in Python.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Build a GUI Calculator With PyQt and Python</title>
      <id>https://realpython.com/courses/build-gui-calculator-pyqt/</id>
      <link href="https://realpython.com/courses/build-gui-calculator-pyqt/"/>
      <updated>2024-06-25T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to create graphical user interface (GUI) applications with Python and PyQt. Once you&#x27;ve covered the basics, you&#x27;ll build a fully functional desktop calculator that can respond to user events with concrete actions.</summary>
      <content type="html">
        &lt;p&gt;Even though web and mobile applications appear to have taken over the software development market, there&amp;rsquo;s still demand for traditional &lt;strong&gt;graphical user interface (GUI)&lt;/strong&gt; desktop applications. If you&amp;rsquo;re interested in building these kinds of applications in Python, then you&amp;rsquo;ll find a wide variety of libraries to choose from. They include &lt;a href=&quot;https://docs.python.org/3/library/tkinter.html&quot;&gt;Tkinter&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-gui-with-wxpython/&quot;&gt;wxPython&lt;/a&gt;, &lt;a href=&quot;https://www.riverbankcomputing.com/software/pyqt/intro&quot;&gt;PyQt&lt;/a&gt;, &lt;a href=&quot;https://wiki.qt.io/Qt_for_Python&quot;&gt;PySide&lt;/a&gt;, and a few others.&lt;/p&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll learn the basics of building GUI desktop applications with Python and &lt;strong&gt;PyQt&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create &lt;strong&gt;graphical user interfaces&lt;/strong&gt; with Python and PyQt&lt;/li&gt;
&lt;li&gt;Connect the &lt;strong&gt;user&amp;rsquo;s events&lt;/strong&gt; on the app&amp;rsquo;s GUI with the &lt;strong&gt;app&amp;rsquo;s logic&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Organize a PyQt app using a proper &lt;strong&gt;project layout&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Create a &lt;strong&gt;fully functional GUI application&lt;/strong&gt; with PyQt&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 #209: Python&#x27;s Command-Line Utilities &amp; Music Information Retrieval Tools</title>
      <id>https://realpython.com/podcasts/rpp/209/</id>
      <link href="https://realpython.com/podcasts/rpp/209/"/>
      <updated>2024-06-21T12:00:00+00:00</updated>
      <summary>What are the built-in Python modules that can work as useful command-line tools? How can these tools add more functionality to Windows machines? 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 built-in Python modules that can work as useful command-line tools? How can these tools add more functionality to Windows machines? 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>Rounding Numbers in Python</title>
      <id>https://realpython.com/courses/rounding-numbers-python/</id>
      <link href="https://realpython.com/courses/rounding-numbers-python/"/>
      <updated>2024-06-18T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn about the mistakes you might make when rounding numbers and how to best manage or avoid them. It&#x27;s a great place to start for the early to intermediate Python developer who&#x27;s interested in using Python for finance, data science, or scientific computing.</summary>
      <content type="html">
        &lt;p&gt;With many businesses &lt;a href=&quot;https://stackoverflow.blog/2017/09/14/python-growing-quickly/&quot;&gt;turning to Python&amp;rsquo;s powerful data science ecosystem&lt;/a&gt; to analyze their data, understanding how to avoid introducing bias into datasets is absolutely vital. If you&amp;rsquo;ve studied some statistics, then you&amp;rsquo;re probably familiar with terms like reporting bias, selection bias, and sampling bias. There&amp;rsquo;s another type of bias that plays an important role when you&amp;rsquo;re dealing with numeric data: rounding bias. &lt;/p&gt;
&lt;p&gt;Understanding how rounding works in Python can help you avoid biasing your dataset. This is an important skill. After all, drawing conclusions from biased data can lead to costly mistakes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Why the way you round numbers is important&lt;/li&gt;
&lt;li&gt;How to round a number according to &lt;strong&gt;various rounding strategies&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to &lt;strong&gt;implement&lt;/strong&gt; each strategy in pure Python&lt;/li&gt;
&lt;li&gt;How &lt;strong&gt;rounding affects data&lt;/strong&gt; and which rounding strategy &lt;strong&gt;minimizes this effect&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;How to round numbers in &lt;strong&gt;NumPy arrays&lt;/strong&gt; and &lt;strong&gt;pandas DataFrames&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;When to apply different rounding strategies&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 #208: Detecting Outliers in Your Data With Python</title>
      <id>https://realpython.com/podcasts/rpp/208/</id>
      <link href="https://realpython.com/podcasts/rpp/208/"/>
      <updated>2024-06-14T12:00:00+00:00</updated>
      <summary>How do you find the most interesting or suspicious points within your data? What libraries and techniques can you use to detect these anomalies with Python? This week on the show, we speak with author Brett Kennedy about his book &quot;Outlier Detection in Python.&quot;</summary>
      <content type="html">
        &lt;p&gt;How do you find the most interesting or suspicious points within your data? What libraries and techniques can you use to detect these anomalies with Python? This week on the show, we speak with author Brett Kennedy about his book &quot;Outlier Detection in Python.&quot;&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Listing All Files in a Directory With Python</title>
      <id>https://realpython.com/courses/listing-all-files-directory/</id>
      <link href="https://realpython.com/courses/listing-all-files-directory/"/>
      <updated>2024-06-11T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll be examining a couple of methods to get a list of files and folders in a directory with Python. You&#x27;ll also use both methods to recursively list directory contents. Finally, you&#x27;ll examine a situation that pits one method against the other.</summary>
      <content type="html">
        &lt;p&gt;Getting a &lt;a href=&quot;https://realpython.com/python-lists-tuples/&quot;&gt;list&lt;/a&gt; of all the &lt;a href=&quot;https://en.wikipedia.org/wiki/Computer_file&quot;&gt;files&lt;/a&gt; and folders in a &lt;a href=&quot;https://en.wikipedia.org/wiki/Directory_(computing)&quot;&gt;directory&lt;/a&gt; is a natural first step for many &lt;strong&gt;file-related operations&lt;/strong&gt; in Python. When looking into it, though, you may be surprised to find various ways to go about it.&lt;/p&gt;
&lt;p&gt;When you&amp;rsquo;re faced with many ways of doing something, it can be a good indication that there&amp;rsquo;s no one-size-fits-all solution to your problems. Most likely, every solution will have its own advantages and trade-offs. This is the case when it comes to getting a list of the contents of a directory in Python.&lt;/p&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll be focusing on the most general-purpose techniques in the &lt;a href=&quot;https://realpython.com/python-pathlib/&quot;&gt;&lt;code&gt;pathlib&lt;/code&gt; module&lt;/a&gt; to list items in a directory, but you&amp;rsquo;ll also learn a bit about some alternative tools.&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>
