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

  
    <entry>
      <title>Building a Python GUI Application With Tkinter</title>
      <id>https://realpython.com/courses/building-gui-application-tkinter/</id>
      <link href="https://realpython.com/courses/building-gui-application-tkinter/"/>
      <updated>2024-05-21T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn the basics of GUI programming with Tkinter, the de facto Python GUI framework. Master GUI programming concepts such as widgets, geometry managers, and event handlers. Then, put it all together by building two applications: a temperature converter and a text editor.</summary>
      <content type="html">
        &lt;p&gt;Python has a lot of &lt;a href=&quot;http://wiki.python.org/moin/GuiProgramming&quot;&gt;GUI frameworks&lt;/a&gt;, but &lt;a href=&quot;https://wiki.python.org/moin/TkInter&quot;&gt;Tkinter&lt;/a&gt; is the only framework that&amp;rsquo;s built into the Python standard library. Tkinter has several strengths. It&amp;rsquo;s &lt;strong&gt;cross-platform&lt;/strong&gt;, so the same code works on Windows, macOS, and Linux. Visual elements are rendered using native operating system elements, so applications built with Tkinter look like they belong on the platform where they&amp;rsquo;re run.&lt;/p&gt;
&lt;p&gt;Although Tkinter is considered the de facto Python GUI framework, it&amp;rsquo;s not without criticism. One notable criticism is that GUIs built with Tkinter look outdated. If you want a shiny, modern interface, then Tkinter may not be what you&amp;rsquo;re looking for.&lt;/p&gt;
&lt;p&gt;However, Tkinter is lightweight and relatively painless to use compared to other frameworks. This makes it a compelling choice for building GUI applications in Python, especially for applications where a modern sheen is unnecessary, and the top priority is to quickly build something that&amp;rsquo;s functional and cross-platform.&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;Get started with Tkinter with a &lt;strong&gt;Hello, World&lt;/strong&gt; application&lt;/li&gt;
&lt;li&gt;Work with &lt;strong&gt;widgets&lt;/strong&gt;, such as buttons and text boxes&lt;/li&gt;
&lt;li&gt;Control your application layout with &lt;strong&gt;geometry managers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Make your applications &lt;strong&gt;interactive&lt;/strong&gt; by associating button clicks with Python functions&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>Basic Data Types in Python: A Quick Exploration</title>
      <id>https://realpython.com/python-data-types/</id>
      <link href="https://realpython.com/python-data-types/"/>
      <updated>2024-05-20T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn about the basic data types that are built into Python, including numbers, strings, bytes, and Booleans.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python has several basic data types that are built into the language. With these types, you can represent numeric values, text and binary data, and Boolean values in your code. So, these data types are the basic building blocks of most Python programs and projects.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn about:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Numeric&lt;/strong&gt; types, such as &lt;strong&gt;&lt;code&gt;int&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;float&lt;/code&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;code&gt;complex&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;str&lt;/code&gt;&lt;/strong&gt; data type, which represents &lt;strong&gt;textual&lt;/strong&gt; data&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;bytes&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;bytearray&lt;/code&gt;&lt;/strong&gt; data types for storing &lt;strong&gt;bytes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Boolean&lt;/strong&gt; values with the &lt;strong&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/strong&gt; data type&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this tutorial, you’ll learn only the basics of each data type. To learn more about a specific data type, you’ll find useful resources in the corresponding section.&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-data-types-update-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-data-types-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 you’ll use to learn about basic data types 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.654fd44c148d.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 “Basic Data Types in Python: A Quick Exploration” 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-data-types/&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: #e5c5ac;&quot; alt=&quot;Basic Data Types in Python&quot; src=&quot;https://files.realpython.com/media/Basic-Data-Types-in-Python_Watermarked.e3dd34457952.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Basic-Data-Types-in-Python_Watermarked.e3dd34457952.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Basic-Data-Types-in-Python_Watermarked.e3dd34457952.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Basic-Data-Types-in-Python_Watermarked.e3dd34457952.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Basic-Data-Types-in-Python_Watermarked.e3dd34457952.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.654fd44c148d.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-data-types/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Basic Data Types in Python: A Quick Exploration&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 the basic data types that are built into Python, like numbers, strings, and Booleans.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;pythons-basic-data-types&quot;&gt;Python’s Basic Data Types&lt;a class=&quot;headerlink&quot; href=&quot;#pythons-basic-data-types&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Python has several &lt;strong&gt;built-in data types&lt;/strong&gt; that you can use out of the box because they’re built into the language. From all the built-in types available, you’ll find that a few of them represent &lt;em&gt;basic&lt;/em&gt; objects, such as numbers, strings and characters, bytes, and Boolean values.&lt;/p&gt;
&lt;p&gt;Note that the term &lt;strong&gt;basic&lt;/strong&gt; refers to objects that can represent data you typically find in real life, such as numbers and text. It doesn’t include composite 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-dicts/&quot;&gt;dictionaries&lt;/a&gt;, and others.&lt;/p&gt;
&lt;p&gt;In Python, the built-in data types that you can consider basic are the following:&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;Class&lt;/th&gt;
&lt;th&gt;Basic Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;#integer-numbers&quot;&gt;&lt;code&gt;int&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Integer numbers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;#floating-point-numbers&quot;&gt;&lt;code&gt;float&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Floating-point numbers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;#complex-numbers&quot;&gt;&lt;code&gt;complex&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Complex numbers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;#strings-and-characters&quot;&gt;&lt;code&gt;str&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Strings and characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;#bytes-and-bytearrays&quot;&gt;&lt;code&gt;bytes&lt;/code&gt;, &lt;code&gt;bytearray&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&quot;#booleans&quot;&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Boolean values&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;In the following sections, you’ll learn the basics of how to create, use, and work with all of these built-in data types in Python.&lt;/p&gt;
&lt;h2 id=&quot;integer-numbers&quot;&gt;Integer Numbers&lt;a class=&quot;headerlink&quot; href=&quot;#integer-numbers&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Integer numbers&lt;/strong&gt; are whole numbers with no decimal places. They can be positive or negative numbers. For example, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;, &lt;code&gt;3&lt;/code&gt;, &lt;code&gt;-1&lt;/code&gt;, &lt;code&gt;-2&lt;/code&gt;, and &lt;code&gt;-3&lt;/code&gt; are all integers. Usually, you’ll use positive integer numbers to count things.&lt;/p&gt;
&lt;p&gt;In Python, the integer data type is represented by the &lt;a href=&quot;https://docs.python.org/3/library/functions.html#int&quot;&gt;&lt;code&gt;int&lt;/code&gt;&lt;/a&gt; class:&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.654fd44c148d.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type&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;go&quot;&gt;&amp;lt;class &#x27;int&#x27;&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.654fd44c148d.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.654fd44c148d.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 following sections, you’ll learn the basics of how to create and work with integer numbers in Python.&lt;/p&gt;
&lt;h3 id=&quot;integer-literals&quot;&gt;Integer Literals&lt;a class=&quot;headerlink&quot; href=&quot;#integer-literals&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;When you need to use integer numbers in your code, you’ll often use integer &lt;a href=&quot;https://docs.python.org/3/reference/lexical_analysis.html#literals&quot;&gt;literals&lt;/a&gt; directly. Literals are constant values of built-in types spelled out literally, such as integers. Python provides a few different ways to create integer literals. The most common way is to use base-ten literals that look the same as integers look in math:&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.654fd44c148d.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;mi&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;42&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;84&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;-84&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&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.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Here, you have three integer numbers: a positive one, a negative one, and zero. Note that to create negative integers, you need to prepend the minus sign (&lt;code&gt;-&lt;/code&gt;) to the number.&lt;/p&gt;
&lt;p&gt;Python has no limit to how long an integer value can be. The only constraint is the amount of memory your system has. Beyond that, an integer can be as long as you need:&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.654fd44c148d.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;mi&quot;&gt;123123123123123123123123123123123123123123123123&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;123123123123123123123123123123123123123123123124&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.654fd44c148d.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.654fd44c148d.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;For a really, really long integer, you &lt;a href=&quot;https://realpython.com/python-news-september-2022/#python-introduced-a-breaking-change-to-fix-a-vulnerability&quot;&gt;can get a &lt;code&gt;ValueError&lt;/code&gt;&lt;/a&gt; when converting it to a string:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;pycon&quot; data-is-repl=&quot;true&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
        &lt;span class=&quot;codeblock__output-toggle&quot; title=&quot;Toggle prompts and output&quot; 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.654fd44c148d.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;mi&quot;&gt;123&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;ValueError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;Exceeds the limit (4300 digits) for integer string conversion;&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;            use sys.set_int_max_str_digits() to increase the limit&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.654fd44c148d.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.654fd44c148d.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;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-data-types/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-data-types/ »&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 #205: Considering Accessibility &amp; Assistive Tech as a Python Developer</title>
      <id>https://realpython.com/podcasts/rpp/205/</id>
      <link href="https://realpython.com/podcasts/rpp/205/"/>
      <updated>2024-05-17T12:00:00+00:00</updated>
      <summary>What&#x27;s it like to learn Python as a visually impaired or blind developer? How can you improve the accessibility of your Python web applications and learn current guidelines? This week on the show, Real Python community member Audrey van Breederode discusses her programming journey, web accessibility, and assistive technology.</summary>
      <content type="html">
        &lt;p&gt;What&#x27;s it like to learn Python as a visually impaired or blind developer? How can you improve the accessibility of your Python web applications and learn current guidelines? This week on the show, Real Python community member Audrey van Breederode discusses her programming journey, web accessibility, and assistive technology.&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 Get the Most Out of PyCon US</title>
      <id>https://realpython.com/pycon-guide/</id>
      <link href="https://realpython.com/pycon-guide/"/>
      <updated>2024-05-15T14:00:00+00:00</updated>
      <summary>In this article, you&#x27;ll learn how you can get the most out of PyCon US. Whether you&#x27;re a first-timer or a seasoned attendee, this guide will help you get ready to have a great PyCon.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Congratulations! You’re going to PyCon US!&lt;/p&gt;
&lt;p&gt;Whether this is your first time or not, going to a conference full of people who love the same thing as you is always a fun experience. There’s so much more to PyCon than just a bunch of people talking about the Python language, and that can be intimidating for first-time attendees. This guide will help you navigate all there is to see and do at PyCon.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://us.pycon.org/2024/&quot;&gt;PyCon US&lt;/a&gt; is the biggest conference centered around the Python language. Originally launched in 2003, this conference has grown exponentially and has even spawned several other &lt;a href=&quot;https://www.python.org/community/workshops/&quot;&gt;PyCons and workshops around the world&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Everyone who attends PyCon will have a different experience, and that’s what makes the conference truly unique. This guide is meant to help you, but you don’t need to follow it strictly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;By the end of this article, you’ll know:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How PyCon consists of &lt;strong&gt;tutorials&lt;/strong&gt;, &lt;strong&gt;conference&lt;/strong&gt;, and &lt;strong&gt;sprints&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;What to do &lt;strong&gt;before&lt;/strong&gt; you go&lt;/li&gt;
&lt;li&gt;What to do &lt;strong&gt;during&lt;/strong&gt; PyCon&lt;/li&gt;
&lt;li&gt;What to do &lt;strong&gt;after&lt;/strong&gt; the event&lt;/li&gt;
&lt;li&gt;How to have a &lt;strong&gt;great&lt;/strong&gt; PyCon&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This guide will have links that are specific to PyCon 2024, but it should be useful for future PyCons as well.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Download:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-tricks-sample-pdf/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-tricks-sample-pdf&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Get a sample chapter from Python Tricks: The Book&lt;/a&gt; that shows you Python’s best practices with simple examples you can apply instantly to write more beautiful + Pythonic code.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;what-pycon-involves&quot;&gt;What PyCon Involves&lt;a class=&quot;headerlink&quot; href=&quot;#what-pycon-involves&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before considering how to get the most out of PyCon, it’s important to first understand what PyCon involves.&lt;/p&gt;
&lt;p&gt;PyCon is broken up into three stages:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tutorials:&lt;/strong&gt; PyCon starts with two days of three-hour workshops, during which you get to learn in depth with instructors. These are great to go to since the class sizes are small, and you can ask questions of the instructors. You should consider going to at least one of these if you can, but they do have an additional cost of $150 per tutorial.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Conference:&lt;/strong&gt; Next, PyCon offers three days of talks. Each presentation lasts for thirty to forty-five minutes, and there are about five talks going on at a time, including a Spanish language charlas track. But that’s not all: there are also open spaces, sponsors, posters, lightning talks, dinners, and so much more.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sprints:&lt;/strong&gt; During this stage, you can take what you’ve learned and apply it! This is a four-day exercise where people group up to work on various open-source projects related to Python. If you’ve got the time, going to one or more sprint days is a great way to practice what you’ve learned, become associated with an open-source project, and network with other smart and talented people. Learn more about sprints in this &lt;a href=&quot;https://pycon.blogspot.com/2016/03/why-not-join-sprints-this-year-at-pycon.html&quot;&gt;blog post&lt;/a&gt; from an earlier year.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Since most PyCon attendees go to the conference part, that’ll be the focus of this article. However, don’t let that deter you from attending the tutorials or sprints if you can!&lt;/p&gt;
&lt;p&gt;You may even learn more technical skills by attending the tutorials rather than listening to the talks. The sprints are great for networking and applying the skills that you’ve already got, as well as learning new ones from the people you’ll be working with.&lt;/p&gt;
&lt;h2 id=&quot;what-to-do-before-you-go&quot;&gt;What to Do Before You Go&lt;a class=&quot;headerlink&quot; href=&quot;#what-to-do-before-you-go&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In general, the more prepared you are for something, the better your experience will be. The same applies to PyCon.&lt;/p&gt;
&lt;p&gt;It’s really helpful to plan and prepare ahead of time, which you’re already doing just by reading this article!&lt;/p&gt;
&lt;p&gt;Look through the &lt;a href=&quot;https://us.pycon.org/2024/schedule/talks/&quot;&gt;talk schedule&lt;/a&gt; and see which talks sound most interesting to you. This doesn’t mean you need to plan out all of the talks that you’re going to see, in every slot possible. But it helps to get an idea of which topics are going to be presented so that you can decide what you’re most interested in.&lt;/p&gt;
&lt;p&gt;Getting the &lt;a href=&quot;https://us.pycon.org/2024/attend/onsite/&quot;&gt;PyCon US mobile app&lt;/a&gt; will help you plan your schedule. This app lets you view the schedule for the talks and add reminders for the ones that you want to attend. If you’re having a hard time picking which talks to go to, you can come prepared with a question or problem that you need to solve. Doing this can help you focus on the topics that are important to you.&lt;/p&gt;
&lt;p&gt;If you can, come a day early to check in and attend the opening reception. The line to check in on the first day is always long, so you’ll save time if you check in the day before. There’s also an opening reception that evening, so you can meet other attendees and speakers, as well as get a chance to check out the various sponsors and their booths.&lt;/p&gt;
&lt;p&gt;If you’re brand-new to PyCon, the &lt;a href=&quot;https://us.pycon.org/2024/events/newcomer-orientation/&quot;&gt;Newcomer Orientation&lt;/a&gt; can help you get caught up on what the conference involves and how you can participate.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/pycon-guide/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/pycon-guide/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python&#x27;s Built-in Exceptions: A Walkthrough With Examples</title>
      <id>https://realpython.com/python-built-in-exceptions/</id>
      <link href="https://realpython.com/python-built-in-exceptions/"/>
      <updated>2024-05-15T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll get to know some of the most commonly used built-in exceptions in Python. You&#x27;ll learn when these exceptions can appear in your code and how to handle them. Finally, you&#x27;ll learn how to raise some of these exceptions in your code.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;Python has a complete set of &lt;strong&gt;built-in exceptions&lt;/strong&gt; that provide a quick and efficient way to handle errors and exceptional situations that may happen in your code. Knowing the most commonly used built-in exceptions is key for you as a Python developer. This knowledge will help you debug code because each exception has a specific meaning that can shed light on your debugging process.&lt;/p&gt;
&lt;p&gt;You’ll also be able to handle and raise most of the built-in exceptions in your Python code, which is a great way to deal with errors and exceptional situations without having to create your own custom exceptions.&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;errors&lt;/strong&gt; and &lt;strong&gt;exceptions&lt;/strong&gt; are in Python&lt;/li&gt;
&lt;li&gt;Understand how Python organizes the &lt;strong&gt;built-in exceptions&lt;/strong&gt; in a &lt;strong&gt;class hierarchy&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Explore the most &lt;strong&gt;commonly used&lt;/strong&gt; built-in exceptions&lt;/li&gt;
&lt;li&gt;Learn how to &lt;strong&gt;handle&lt;/strong&gt; and &lt;strong&gt;raise&lt;/strong&gt; built-in exceptions in your code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To smoothly walk through this tutorial, you should be familiar with some core concepts in Python. These concepts include Python &lt;a href=&quot;https://realpython.com/python-classes/&quot;&gt;classes&lt;/a&gt;, class &lt;a href=&quot;https://realpython.com/python-classes/#class-hierarchies&quot;&gt;hierarchies&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-exceptions/&quot;&gt;exceptions&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/python-exceptions/#handling-exceptions-with-the-try-and-except-block&quot;&gt;&lt;code&gt;try&lt;/code&gt; … &lt;code&gt;except&lt;/code&gt;&lt;/a&gt; blocks, and the &lt;a href=&quot;https://realpython.com/python-raise-exception/&quot;&gt;&lt;code&gt;raise&lt;/code&gt;&lt;/a&gt; statement.&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-built-in-exceptions-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-built-in-exceptions-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 Python’s built-in exceptions.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;errors-and-exceptions-in-python&quot;&gt;Errors and Exceptions in Python&lt;a class=&quot;headerlink&quot; href=&quot;#errors-and-exceptions-in-python&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Errors&lt;/strong&gt; and &lt;strong&gt;exceptions&lt;/strong&gt; are important concepts in programming, and you’ll probably spend a considerable amount of time dealing with them in your programming career. &lt;strong&gt;Errors&lt;/strong&gt; are concrete conditions, such as &lt;strong&gt;syntax&lt;/strong&gt; and &lt;strong&gt;logical&lt;/strong&gt; errors, that make your code work incorrectly or even crash.&lt;/p&gt;
&lt;p&gt;Often, you can fix errors by updating or modifying the code, installing a new version of a dependency, checking the code’s logic, and so on.&lt;/p&gt;
&lt;p&gt;For example, say you need to make sure that a given &lt;a href=&quot;https://realpython.com/python-strings/&quot;&gt;string&lt;/a&gt; has a certain number of characters. In this case, you can 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:&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.654fd44c148d.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Pythonista&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
  File &lt;span class=&quot;nb&quot;&gt;&quot;&amp;lt;input&amp;gt;&quot;&lt;/span&gt;, line &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;SyntaxError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;cannot assign to function call here.&lt;/span&gt;
&lt;span class=&quot;x&quot;&gt;    Maybe you meant &#x27;==&#x27; instead of &#x27;=&#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.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, you use the wrong &lt;a href=&quot;https://realpython.com/python-operators-expressions/&quot;&gt;operator&lt;/a&gt;. Instead of using the equality &lt;a href=&quot;https://realpython.com/python-operators-expressions/#comparison-operators-and-expressions-in-python&quot;&gt;comparison operator&lt;/a&gt;, you use the &lt;a href=&quot;https://realpython.com/python-assignment-operator/&quot;&gt;assignment operator&lt;/a&gt;. This code raises a &lt;a href=&quot;https://realpython.com/invalid-syntax-python/&quot;&gt;&lt;code&gt;SyntaxError&lt;/code&gt;&lt;/a&gt;, which represents a syntax error as its name describes.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In the above code, you’ll note how nicely the error message suggests a possible solution for correcting the code. Starting in version &lt;a href=&quot;https://realpython.com/python310-new-features/&quot;&gt;3.10&lt;/a&gt;, the Python core developers have put a lot of effort into improving the &lt;a href=&quot;https://realpython.com/python310-new-features/#better-error-messages&quot;&gt;error messages&lt;/a&gt; to make them more friendly and useful for debugging.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;To fix the error, you need to localize the affected code and correct the syntax. This action will remove the error:&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.654fd44c148d.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Pythonista&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&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.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now the code works correctly, and the &lt;code&gt;SyntaxError&lt;/code&gt; is gone. So, your code won’t break, and your program will continue its normal execution.&lt;/p&gt;
&lt;p&gt;There’s something to learn from the above example. You can fix errors, but you can’t &lt;em&gt;handle&lt;/em&gt; them. In other words, if you have a syntax error like the one in the example, then you won’t be able to handle that error and make the code run. You need to correct the syntax.&lt;/p&gt;
&lt;p&gt;On the other hand, &lt;strong&gt;exceptions&lt;/strong&gt; are events that interrupt the execution of a program. As their name suggests, exceptions occur in &lt;em&gt;exceptional&lt;/em&gt; situations that should or shouldn’t happen. So, to prevent your program from crashing after an exception, you must handle the exception with the appropriate exception-handling mechanism.&lt;/p&gt;
&lt;p&gt;To better understand exceptions, say that you have a Python expression like &lt;code&gt;a + b&lt;/code&gt;. This expression will work if &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are both strings or &lt;a href=&quot;https://realpython.com/python-numbers/&quot;&gt;numbers&lt;/a&gt;:&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.654fd44c148d.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;7&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.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In this example, the code works correctly because &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are both numbers. However, the expression raises an exception if &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are of types that can’t be added together:&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.654fd44c148d.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;4&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;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
  File &lt;span class=&quot;nb&quot;&gt;&quot;&amp;lt;input&amp;gt;&quot;&lt;/span&gt;, line &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;, in &lt;span class=&quot;n&quot;&gt;&amp;lt;module&amp;gt;&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;pm&quot;&gt;~~^~~&lt;/span&gt;
&lt;span class=&quot;gr&quot;&gt;TypeError&lt;/span&gt;: &lt;span class=&quot;n&quot;&gt;can only concatenate str (not &quot;int&quot;) to str&lt;/span&gt;
&lt;/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.654fd44c148d.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.654fd44c148d.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;Because &lt;code&gt;a&lt;/code&gt; is a string and &lt;code&gt;b&lt;/code&gt; is a number, your code fails with a &lt;code&gt;TypeError&lt;/code&gt; exception. Since there is no way to add text and numbers, your code has faced an exceptional situation.&lt;/p&gt;
&lt;p&gt;Python uses classes to represent exceptions and errors. These classes are generically known as &lt;strong&gt;exceptions&lt;/strong&gt;, regardless of what a concrete class represents, an exception or an error. Exception classes give us information about an &lt;em&gt;exceptional situation&lt;/em&gt; and also &lt;em&gt;errors&lt;/em&gt; detected during the program’s execution.&lt;/p&gt;
&lt;p&gt;The first example in this section shows a syntax error in action. The &lt;code&gt;SyntaxError&lt;/code&gt; class represents an error but it’s implemented as a Python exception. This could be confusing, but Python uses exception classes for both errors and exceptions.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-built-in-exceptions/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-built-in-exceptions/ »&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: What Are CRUD Operations?</title>
      <id>https://realpython.com/quizzes/crud-operations/</id>
      <link href="https://realpython.com/quizzes/crud-operations/"/>
      <updated>2024-05-15T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll revisit the key concepts and techniques related to CRUD operations. These operations are fundamental to any system that interacts with a database, and understanding them is crucial for effective data management.</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/crud-operations/&quot;&gt;CRUD Operations&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit the key concepts and techniques related to CRUD operations. 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>HTML and CSS Foundations for Python Developers</title>
      <id>https://realpython.com/courses/html-css-foundations/</id>
      <link href="https://realpython.com/courses/html-css-foundations/"/>
      <updated>2024-05-14T14:00:00+00:00</updated>
      <summary>There&#x27;s no way around HTML and CSS when you want to build web apps. Even if you&#x27;re not aiming to become a web developer, knowing the basics of HTML and CSS will help you understand the Web better. In this video course, you&#x27;ll get an introduction to HTML and CSS for Python programmers.</summary>
      <content type="html">
        &lt;p&gt;When you want to build websites as a Python programmer, there&amp;rsquo;s no way around HTML and CSS.
Almost every website on the Internet is built with &lt;strong&gt;HTML markup&lt;/strong&gt; to structure the page.
To make a website look nice, you can style HTML with &lt;strong&gt;CSS&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re interested in web development with Python, then knowing HTML and CSS will help you understand web frameworks like &lt;strong&gt;Django&lt;/strong&gt; and &lt;strong&gt;Flask&lt;/strong&gt; better.
But even if you&amp;rsquo;re just getting started with Python, HTML and CSS can enable you to create small websites to impress your friends.&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;Structure a basic &lt;strong&gt;HTML&lt;/strong&gt; file&lt;/li&gt;
&lt;li&gt;View and inspect HTML in your &lt;strong&gt;browser&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Insert &lt;strong&gt;images&lt;/strong&gt; and page &lt;strong&gt;links&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Style a website with &lt;strong&gt;CSS&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Format HTML with &lt;strong&gt;accessibility&lt;/strong&gt; in mind&lt;/li&gt;
&lt;li&gt;Use Python to &lt;strong&gt;write and parse&lt;/strong&gt; HTML code&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>What Is the __pycache__ Folder in Python?</title>
      <id>https://realpython.com/python-pycache/</id>
      <link href="https://realpython.com/python-pycache/"/>
      <updated>2024-05-13T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll explore Python&#x27;s __pycache__ folder. You&#x27;ll learn about when and why the interpreter creates these folders, and you&#x27;ll customize their default behavior. Finally, you&#x27;ll take a look under the hood of the cached .pyc files.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;When you develop a self-contained Python script, you might not notice anything unusual about your directory structure. However, as soon as your project becomes more complex, you’ll often decide to extract parts of the functionality into additional &lt;a href=&quot;https://realpython.com/python-modules-packages/&quot;&gt;modules or packages&lt;/a&gt;. That’s when you may start to see a &lt;code&gt;__pycache__&lt;/code&gt; folder appearing out of nowhere next to your source files in seemingly random places:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;project/
│
├── mathematics/
│   │
&lt;span class=&quot;hll&quot;&gt;│   ├── __pycache__/
&lt;/span&gt;│   │
│   ├── arithmetic/
│   │   ├── __init__.py
│   │   ├── add.py
│   │   └── sub.py
│   │
│   ├── geometry/
│   │   │
&lt;span class=&quot;hll&quot;&gt;│   │   ├── __pycache__/
&lt;/span&gt;│   │   │
│   │   ├── __init__.py
│   │   └── shapes.py
│   │
│   └── __init__.py
│
└── calculator.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Notice that the &lt;code&gt;__pycache__&lt;/code&gt; folder can be present at different levels in your project’s directory tree when you have multiple subpackages nested in one another. At the same time, other packages or folders with your Python source files may not contain this mysterious cache directory.&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 maintain a cleaner workspace, many &lt;a href=&quot;https://realpython.com/python-ides-code-editors-guide/&quot;&gt;Python IDEs and code editors&lt;/a&gt; are configured out-of-the-box to hide the &lt;code&gt;__pycache__&lt;/code&gt; folders from you, even if those folders exist on your file system.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You may encounter a similar situation after you clone a remote &lt;a href=&quot;https://realpython.com/python-git-github-intro/&quot;&gt;Git repository&lt;/a&gt; with a Python project and run the underlying code. &lt;strong&gt;So, what causes the &lt;code&gt;__pycache__&lt;/code&gt; folder to appear, and for what purpose?&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-pycache-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-pycache-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 the &lt;strong&gt;pycache&lt;/strong&gt; folder 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.654fd44c148d.svg#@quiz&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt; Take the Quiz:&lt;/strong&gt;&lt;/mark&gt; Test your knowledge with our interactive “What Is the __pycache__ Folder 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-pycache/&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;What Is the __pycache__ Folder in Python?&quot; src=&quot;https://files.realpython.com/media/What-is-__pycache___Watermarked.0e2367687d70.jpg&quot; width=&quot;1920&quot; height=&quot;1080&quot; srcset=&quot;/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/What-is-__pycache___Watermarked.0e2367687d70.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/What-is-__pycache___Watermarked.0e2367687d70.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/What-is-__pycache___Watermarked.0e2367687d70.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/What-is-__pycache___Watermarked.0e2367687d70.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.654fd44c148d.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-pycache/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;What Is the __pycache__ Folder 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 have the opportunity to test your knowledge of the __pycache__ folder, including when, where, and why Python creates these folders.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;in-short-it-makes-importing-python-modules-faster&quot;&gt;In Short: It Makes Importing Python Modules Faster&lt;a class=&quot;headerlink&quot; href=&quot;#in-short-it-makes-importing-python-modules-faster&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Even though Python is an &lt;a href=&quot;https://en.wikipedia.org/wiki/Interpreter_(computing)&quot;&gt;interpreted programming language&lt;/a&gt;, its interpreter doesn’t operate directly on your Python code, which would be very slow. Instead, when you &lt;a href=&quot;https://realpython.com/run-python-scripts/&quot;&gt;run a Python script&lt;/a&gt; or &lt;a href=&quot;https://realpython.com/python-import/&quot;&gt;import&lt;/a&gt; a Python module, the interpreter compiles your high-level Python source code into &lt;a href=&quot;https://en.wikipedia.org/wiki/Bytecode&quot;&gt;bytecode&lt;/a&gt;, which is an intermediate binary representation of the code.&lt;/p&gt;
&lt;p&gt;This bytecode enables the interpreter to skip recurring steps, such as &lt;a href=&quot;https://realpython.com/cpython-source-code-guide/#lexing-and-parsing&quot;&gt;lexing and parsing&lt;/a&gt; the code into an &lt;a href=&quot;https://en.wikipedia.org/wiki/Abstract_syntax_tree&quot;&gt;abstract syntax tree&lt;/a&gt; and validating its correctness every time you run the same program. As long as the underlying source code hasn’t changed, Python can reuse the &lt;a href=&quot;https://en.wikipedia.org/wiki/Intermediate_representation&quot;&gt;intermediate representation&lt;/a&gt;, which is immediately ready for execution. This saves time, speeding up your script’s startup time.&lt;/p&gt;
&lt;p&gt;Remember that while loading the compiled bytecode from &lt;code&gt;__pycache__&lt;/code&gt; makes Python modules import faster, it doesn’t affect their execution speed!&lt;/p&gt;
&lt;div class=&quot;card mb-3&quot; id=&quot;collapse_cardd97415&quot;&gt;
&lt;div class=&quot;card-header border-0&quot;&gt;
&lt;p class=&quot;m-0&quot;&gt;
    &lt;button class=&quot;btn w-100&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapsed97415&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapsed97415&quot; markdown=&quot;1&quot;&gt;&lt;span class=&quot;float-left&quot; markdown=&quot;1&quot;&gt;Bytecode vs Machine Code&lt;/span&gt;&lt;span class=&quot;float-right text-muted&quot;&gt;Show/Hide&lt;/span&gt;&lt;/button&gt;
  &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;collapse js-collapsible-section&quot; data-parent=&quot;#collapse_cardd97415&quot; id=&quot;collapsed97415&quot;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;p&gt;Why bother with bytecode at all instead of compiling the code straight to the low-level &lt;a href=&quot;https://en.wikipedia.org/wiki/Machine_code&quot;&gt;machine code&lt;/a&gt;? While machine code is what executes on the hardware, providing the ultimate performance, it’s not as &lt;em&gt;portable&lt;/em&gt; or quick to produce as bytecode.&lt;/p&gt;
&lt;p&gt;Machine code is a set of binary instructions understood by your specific CPU architecture, wrapped in a container format like &lt;a href=&quot;https://en.wikipedia.org/wiki/.exe&quot;&gt;EXE&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Executable_and_Linkable_Format&quot;&gt;ELF&lt;/a&gt;, or &lt;a href=&quot;https://en.wikipedia.org/wiki/Mach-O&quot;&gt;Mach-O&lt;/a&gt;, depending on the operating system. In contrast, bytecode provides a platform-independent abstraction layer and is typically quicker to compile.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Python uses local &lt;code&gt;__pycache__&lt;/code&gt; folders to store the compiled bytecode of &lt;strong&gt;imported modules&lt;/strong&gt; in your project. On subsequent runs, the interpreter will try to load precompiled versions of modules from these folders, provided they’re up-to-date with the corresponding source files. Note that this &lt;a href=&quot;https://realpython.com/lru-cache-python/&quot;&gt;caching&lt;/a&gt; mechanism only gets triggered for modules you &lt;em&gt;import&lt;/em&gt; in your code rather than executing as scripts in the terminal.&lt;/p&gt;
&lt;p&gt;In addition to this &lt;strong&gt;on-disk bytecode caching&lt;/strong&gt;, Python keeps an &lt;strong&gt;in-memory cache of modules&lt;/strong&gt;, which you can access through the &lt;a href=&quot;https://docs.python.org/3/library/sys.html#sys.modules&quot;&gt;&lt;code&gt;sys.modules&lt;/code&gt;&lt;/a&gt; dictionary. It ensures that when you import the same module multiple times from different places within your program, Python will use the already imported module without needing to reload or recompile it. Both mechanisms work together to reduce the overhead of importing Python modules.&lt;/p&gt;
&lt;p&gt;Next, you’re going to find out exactly how much faster Python loads the cached bytecode as opposed to compiling the source code on the fly when you import a module.&lt;/p&gt;
&lt;h2 id=&quot;how-much-faster-is-loading-modules-from-cache&quot;&gt;How Much Faster Is Loading Modules From Cache?&lt;a class=&quot;headerlink&quot; href=&quot;#how-much-faster-is-loading-modules-from-cache&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The caching happens behind the scenes and usually goes unnoticed since Python is quite rapid at compiling the bytecode. Besides, unless you often run short-lived Python scripts, the compilation step remains insignificant when compared to the total execution time. That said, without caching, the overhead associated with bytecode compilation could add up if you had lots of modules and imported them many times over.&lt;/p&gt;
&lt;p&gt;To measure the difference in &lt;strong&gt;import time&lt;/strong&gt; between a cached and uncached module, you can pass the &lt;a href=&quot;https://realpython.com/python37-new-features/#developer-tricks&quot;&gt;&lt;code&gt;-X importtime&lt;/code&gt;&lt;/a&gt; option to the &lt;code&gt;python&lt;/code&gt; command or set the equivalent &lt;a href=&quot;https://docs.python.org/3.7/using/cmdline.html#envvar-PYTHONPROFILEIMPORTTIME&quot;&gt;&lt;code&gt;PYTHONPROFILEIMPORTTIME&lt;/code&gt;&lt;/a&gt; environment variable. When this option is enabled, Python will display a table summarizing how long it took to import each module, including the cumulative time in case a module depends on other modules.&lt;/p&gt;
&lt;p&gt;Suppose you had a &lt;code&gt;calculator.py&lt;/code&gt; script that imports and calls a utility &lt;a href=&quot;https://realpython.com/defining-your-own-python-function/&quot;&gt;function&lt;/a&gt; from a local &lt;code&gt;arithmetic.py&lt;/code&gt; module:&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;calculator.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;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;arithmetic&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;add&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/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.654fd44c148d.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.654fd44c148d.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 imported module defines a single function:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    &lt;span class=&quot;mr-2&quot; aria-label=&quot;Filename&quot;&gt;&lt;code style=&quot;color: inherit;&quot;&gt;arithmetic.py&lt;/code&gt;&lt;/span&gt;
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&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.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, the main script delegates the addition of two numbers, three and four, to the &lt;code&gt;add()&lt;/code&gt; function imported from the &lt;code&gt;arithmetic&lt;/code&gt; module.&lt;/p&gt;
&lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Even though you use the &lt;code&gt;from ... import&lt;/code&gt; syntax, which only brings the specified symbol into your current &lt;a href=&quot;https://realpython.com/python-namespaces-scope/&quot;&gt;namespace&lt;/a&gt;, Python reads and compiles the entire module anyway. Moreover, &lt;a href=&quot;https://www.flake8rules.com/rules/F401.html&quot;&gt;unused imports&lt;/a&gt; would also trigger the compilation.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The first time you run your script, Python compiles and saves the bytecode of the module you imported into a local &lt;code&gt;__pycache__&lt;/code&gt; folder. If such a folder doesn’t already exist, then Python automatically creates one before moving on. Now, when you execute your script again, Python should find and load the cached bytecode as long as you didn’t alter the associated source code.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-pycache/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-pycache/ »&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 #204: Querying OpenStreetMaps via API &amp; Lazy Evaluation in Python</title>
      <id>https://realpython.com/podcasts/rpp/204/</id>
      <link href="https://realpython.com/podcasts/rpp/204/"/>
      <updated>2024-05-10T12:00:00+00:00</updated>
      <summary>Would you like to get more practice working with APIs in Python? How about exploring the globe using the data from OpenStreetMap? 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;Would you like to get more practice working with APIs in Python? How about exploring the globe using the data from OpenStreetMap? 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>PyTorch vs TensorFlow for Your Python Deep Learning Project</title>
      <id>https://realpython.com/pytorch-vs-tensorflow/</id>
      <link href="https://realpython.com/pytorch-vs-tensorflow/"/>
      <updated>2024-05-08T14:00:00+00:00</updated>
      <summary>PyTorch vs Tensorflow: Which one should you use? Learn about these two popular deep learning libraries and how to choose the best one for your project.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;PyTorch vs TensorFlow: What’s the difference? Both are open-source Python libraries that use graphs to perform numerical computations on data in deep learning applications. Both are used extensively in academic research and commercial code. Both are extended by a variety of APIs, cloud computing platforms, and model repositories.&lt;/p&gt;
&lt;p&gt;If they’re so similar, then how do you decide which one is best for your project?&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 &lt;strong&gt;PyTorch&lt;/strong&gt; and &lt;strong&gt;TensorFlow&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;tools&lt;/strong&gt; and &lt;strong&gt;resources&lt;/strong&gt; are available for each&lt;/li&gt;
&lt;li&gt;How to choose the &lt;strong&gt;best option&lt;/strong&gt; for your specific use case&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You’ll start by taking a close look at both platforms, beginning with the slightly older TensorFlow. Then, you’ll explore PyTorch and some considerations to help you determine which choice is best for your project. Let’s get started!&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 Decision Guide:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/pytorch-vs-tensorflow-update-pdf/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-pytorch-vs-tensorflow-update-pdf&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free decision guide&lt;/a&gt; that will help you choose between PyTorch and TensorFlow for your Python deep learning project.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;what-is-tensorflow&quot;&gt;What Is TensorFlow?&lt;a class=&quot;headerlink&quot; href=&quot;#what-is-tensorflow&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;TensorFlow was developed by Google and released as open-source in 2015. It grew out of Google’s homegrown machine learning software, which was refactored and optimized for use in production.&lt;/p&gt;
&lt;p&gt;The name “TensorFlow” describes how you organize and perform operations on data. The basic data structure for both TensorFlow and PyTorch is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Tensor&quot;&gt;tensor&lt;/a&gt;. When you use TensorFlow, you perform operations on the data in these tensors by building a &lt;a href=&quot;https://www.quora.com/What-are-the-differences-between-Data-flow-model-and-State-machine-model?&quot;&gt;stateful dataflow graph&lt;/a&gt;, kind of like a flowchart that remembers past events.&lt;/p&gt;
&lt;h3 id=&quot;who-uses-tensorflow&quot;&gt;Who Uses TensorFlow?&lt;a class=&quot;headerlink&quot; href=&quot;#who-uses-tensorflow&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;TensorFlow has a reputation for being a production-grade deep learning library. It has a large and active user base and a proliferation of official and third-party tools and platforms for training, deploying, and serving models.&lt;/p&gt;
&lt;p&gt;After PyTorch was released in 2016, TensorFlow declined in popularity. But in late 2019, Google released &lt;a href=&quot;https://blog.tensorflow.org/2019/09/tensorflow-20-is-now-available.html&quot;&gt;TensorFlow 2.0&lt;/a&gt;—a major update that simplified the library and made it more user-friendly, leading to renewed interest among the machine learning community. &lt;/p&gt;
&lt;h3 id=&quot;code-style-and-function&quot;&gt;Code Style and Function&lt;a class=&quot;headerlink&quot; href=&quot;#code-style-and-function&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In TensorFlow 2.0, you can use &lt;a href=&quot;https://www.tensorflow.org/guide/eager&quot;&gt;eager execution&lt;/a&gt;, which is how Python normally works. Eager execution evaluates operations immediately, so you can write your code using Python control flow rather than graph control flow. To see this in action, you’ll take a look at how you would multiply two tensors using both Tensorflow 1.0 and 2.0.&lt;/p&gt;
&lt;p&gt;To start, here’s an example of how to multiply tensors using TensorFlow 2.0. With eager execution, all you need is &lt;code&gt;tf.math.multiply()&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;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.654fd44c148d.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;tensorflow&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;tf&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;x&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;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;4.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;6.&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;y&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;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.&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;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&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;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&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;m&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&amp;lt;tf.Tensor: shape=(3, 3), dtype=float32, numpy=&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;array([[ 2.,  4.,  6.],&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;       [ 6., 12., 18.],&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;       [10., 20., 30.]], dtype=float32)&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.654fd44c148d.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.654fd44c148d.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, you declare your tensors using Python’s list notation, and &lt;a href=&quot;https://www.tensorflow.org/api_docs/python/tf/math/multiply&quot;&gt;&lt;code&gt;tf.math.multiply()&lt;/code&gt;&lt;/a&gt; executes the &lt;strong&gt;element-wise multiplication&lt;/strong&gt; immediately when you call it.&lt;/p&gt;
&lt;p&gt;Before TensorFlow 2.0, you had to manually stitch together an &lt;a href=&quot;https://en.wikipedia.org/wiki/Abstract_syntax_tree&quot;&gt;abstract syntax tree&lt;/a&gt; by making &lt;code&gt;tf.*&lt;/code&gt; API calls. You then had to pass a set of output tensors and input tensors to a &lt;code&gt;session.run()&lt;/code&gt; call and manually compile the model. &lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Session&lt;/code&gt; object is a &lt;a href=&quot;https://www.tensorflow.org/api_docs/python/tf/compat/v1/Session&quot;&gt;class for running TensorFlow operations&lt;/a&gt;. It contains the environment in which &lt;code&gt;Tensor&lt;/code&gt; objects are evaluated and &lt;code&gt;Operation&lt;/code&gt; objects are executed, and it can own resources like &lt;code&gt;tf.Variable&lt;/code&gt; objects. The most common way to use a &lt;code&gt;Session&lt;/code&gt; is as a &lt;a href=&quot;https://realpython.com/python-with-statement/&quot;&gt;context manager&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To see how a &lt;code&gt;Session&lt;/code&gt; is used in this way, here’s an example of how you multiply two tensors using the old TensorFlow 1.0 method:&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.654fd44c148d.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;tensorflow&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;tf&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;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;compat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;disable_eager_execution&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;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;compat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;float32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;x&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;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;compat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;float32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;y&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;multiply&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&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;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&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;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;compat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;feed_dict&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;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;4.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;6.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]}&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;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;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;[[ 2.  4.  6.]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; [ 6. 12. 18.]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt; [10. 20. 30.]]&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.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This code uses TensorFlow 2.x’s &lt;code&gt;tf.compat&lt;/code&gt; API to access TensorFlow 1.x methods and disable eager execution. &lt;/p&gt;
&lt;p&gt;You first declare the input tensors &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; using &lt;a href=&quot;https://www.tensorflow.org/api_docs/python/tf/compat/v1/placeholder&quot;&gt;&lt;code&gt;tf.compat.v1.placeholder&lt;/code&gt;&lt;/a&gt; tensor objects. Then you define the operation to perform on them. Note that nothing has been calculated at this point.&lt;/p&gt;
&lt;p&gt;Next, using the &lt;code&gt;tf.Session&lt;/code&gt; object as a context manager, you create a container to encapsulate the runtime environment and do the multiplication by feeding real values into the placeholders with a &lt;code&gt;feed_dict&lt;/code&gt;. Finally, still inside the session, you &lt;a href=&quot;https://realpython.com/python-print/&quot;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt; the result.&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; Keep in mind that because TensorFlow 1.0 has been deprecated, it probably isn’t the best option for your future projects, and you should stick with using TensorFlow 2.0.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/pytorch-vs-tensorflow/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/pytorch-vs-tensorflow/ »&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>Flattening a List of Lists in Python</title>
      <id>https://realpython.com/courses/flatten-list-of-lists/</id>
      <link href="https://realpython.com/courses/flatten-list-of-lists/"/>
      <updated>2024-05-07T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to flatten a list of lists in Python. You&#x27;ll use different tools and techniques to accomplish this task. First, you&#x27;ll use a loop along with the .extend() method of list. Then you&#x27;ll explore other tools, including reduce(), sum(), itertools.chain(), and more.</summary>
      <content type="html">
        &lt;p&gt;Sometimes, when you&amp;rsquo;re working with data, you may have the data as a list of nested lists. A common operation is to &lt;strong&gt;flatten&lt;/strong&gt; this data into a one-dimensional list in Python. Flattening a list involves converting a multidimensional list, such as a matrix, into a one-dimensional list.&lt;/p&gt;
&lt;p&gt;In this video course, you&amp;rsquo;ll learn how to do that 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>Python News: What&#x27;s New From April 2024</title>
      <id>https://realpython.com/python-news-april-2024/</id>
      <link href="https://realpython.com/python-news-april-2024/"/>
      <updated>2024-05-06T14:00:00+00:00</updated>
      <summary>In April 2024, the last alpha release of Python 3.13 was published. At the same time, the PSF announced some great news, and PyCon US 2024 opened its call for volunteers. Some fundamental Python projects, such as Django, pandas, and Pillow, also released new versions.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;In April 2024, Python’s core development team released versions &lt;strong&gt;3.13.0a6&lt;/strong&gt; and &lt;strong&gt;3.12.3&lt;/strong&gt; of the language! The former received several exciting features, improvements, and optimizations, while the latter got more than 300 commits for security improvements and bug fixes.&lt;/p&gt;
&lt;p&gt;The 3.13.0a6 release is the last alpha release. In the first half of May, the code will be frozen and won’t accept new features. Note that 3.13.0a6 is a &lt;a href=&quot;https://realpython.com/python-pre-release/&quot;&gt;pre-release&lt;/a&gt;, so you shouldn’t use it for production environments. However, it provides a great way to try out some new and exciting language features.&lt;/p&gt;
&lt;p&gt;There is also great news about PyCon US 2024, which opened its call for volunteers.&lt;/p&gt;
&lt;p&gt;Let’s dive into the most exciting &lt;strong&gt;Python news&lt;/strong&gt; from April 2024!&lt;/p&gt;
&lt;h2 id=&quot;python-3130-alpha-6-and-3123-arrive&quot;&gt;Python 3.13.0 Alpha 6 and 3.12.3 Arrive&lt;a class=&quot;headerlink&quot; href=&quot;#python-3130-alpha-6-and-3123-arrive&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This April, Python &lt;a href=&quot;https://blog.python.org/2024/04/python-3123-and-3130a6-released.html&quot;&gt;released&lt;/a&gt; its sixth &lt;strong&gt;alpha preview release&lt;/strong&gt;, 3.13.0a6. This version is the last alpha release, as Python 3.13 will enter the &lt;strong&gt;beta phase&lt;/strong&gt; on May 7. Once in beta, it won’t accept any new features. &lt;/p&gt;
&lt;p&gt;Python 3.13 brings the following new features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#improved-error-messages&quot;&gt;Colorized exception tracebacks&lt;/a&gt; are now the default behavior in the interactive interpreter or &lt;a href=&quot;https://realpython.com/python-repl/&quot;&gt;REPL&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;An &lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#experimental-jit-compiler&quot;&gt;experimental JIT compiler&lt;/a&gt; that provides the groundwork for significant performance improvements.&lt;/li&gt;
&lt;li&gt;The garbage collector is now &lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#incremental-garbage-collection&quot;&gt;incremental&lt;/a&gt;, which should make the garbage collection process more efficient.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#other-language-changes&quot;&gt;Stripped indentation in docstrings&lt;/a&gt; reduces memory usage and the size of &lt;code&gt;.pyc&lt;/code&gt; files.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Meanwhile, the standard library comes with these new features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://docs.python.org/dev/library/dbm.html&quot;&gt;&lt;code&gt;dbm&lt;/code&gt;&lt;/a&gt; module has a new &lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#id1&quot;&gt;&lt;code&gt;dbm.sqlite3&lt;/code&gt;&lt;/a&gt; backend for creating new files.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://peps.python.org/pep-0594/&quot;&gt;PEP 594&lt;/a&gt; scheduled removals of many deprecated modules: &lt;code&gt;aifc&lt;/code&gt;, &lt;code&gt;audioop&lt;/code&gt;, &lt;code&gt;chunk&lt;/code&gt;, &lt;code&gt;cgi&lt;/code&gt;, &lt;code&gt;cgitb&lt;/code&gt;, &lt;code&gt;crypt&lt;/code&gt;, &lt;code&gt;imghdr&lt;/code&gt;, &lt;code&gt;mailcap&lt;/code&gt;, &lt;code&gt;msilib&lt;/code&gt;, &lt;code&gt;nis&lt;/code&gt;, &lt;code&gt;nntplib&lt;/code&gt;, &lt;code&gt;ossaudiodev&lt;/code&gt;, &lt;code&gt;pipes&lt;/code&gt;, &lt;code&gt;sndhdr&lt;/code&gt;, &lt;code&gt;spwd&lt;/code&gt;, &lt;code&gt;sunau&lt;/code&gt;, &lt;code&gt;telnetlib&lt;/code&gt;, &lt;code&gt;uu&lt;/code&gt;, &lt;code&gt;xdrlib&lt;/code&gt;, &lt;code&gt;lib2to3&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Many deprecated classes, functions, and methods (dead batteries) were &lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#removed&quot;&gt;removed&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.python.org/dev/whatsnew/3.13.html#deprecated&quot;&gt;New deprecations&lt;/a&gt; appeared, and many of them were scheduled for removal in Python 3.15 or 3.16.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a detailed list of changes, additions, and removals, you can check out the &lt;a href=&quot;https://docs.python.org/3.12/whatsnew/changelog.html#python-3-13-0-alpha-6&quot;&gt;Changelog&lt;/a&gt; document. The next pre-release of Python 3.13 will be 3.13.0b1, which is currently scheduled for May 7.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/python-news-april-2024/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-news-april-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 #203: Embarking on a Relaxed and Friendly Python Coding Journey</title>
      <id>https://realpython.com/podcasts/rpp/203/</id>
      <link href="https://realpython.com/podcasts/rpp/203/"/>
      <updated>2024-05-03T12:00:00+00:00</updated>
      <summary>Do you get stressed while trying to learn Python? Do you prefer to build small programs or projects as you continue your coding journey? This week on the show, Real Python author Stephen Gruppetta is here to talk about his new book, &quot;The Python Coding Book.&quot;</summary>
      <content type="html">
        &lt;p&gt;Do you get stressed while trying to learn Python? Do you prefer to build small programs or projects as you continue your coding journey? This week on the show, Real Python author Stephen Gruppetta is here to talk about his new book, &quot;The Python Coding Book.&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>Quiz: The Python calendar Module</title>
      <id>https://realpython.com/quizzes/python-calendar-module/</id>
      <link href="https://realpython.com/quizzes/python-calendar-module/"/>
      <updated>2024-05-02T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of the calendar module in Python. It&#x27;ll evaluate your proficiency in manipulating, customizing, and displaying calendars directly within your terminal. By working through this quiz, you&#x27;ll revisit the fundamental functions and methods provided by the calendar module.</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-calendar-module/&quot;&gt;creating calendars in Python&lt;/a&gt; using the &lt;code&gt;calendar&lt;/code&gt; module.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit the fundamental functions and methods provided by the &lt;code&gt;calendar&lt;/code&gt; module.&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 Sequences: A Comprehensive Guide</title>
      <id>https://realpython.com/python-sequences/</id>
      <link href="https://realpython.com/python-sequences/"/>
      <updated>2024-05-01T14:00:00+00:00</updated>
      <summary>This tutorial dives into Python sequences, which is one of the main categories of data types. You&#x27;ll learn about the properties that make an object a sequence and how to create user-defined sequences.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;A phrase you’ll often hear is that everything in Python is an object, and every object has a type. This points to the importance of data types in Python. However, often what an object can do is more important than what it is. So, it’s useful to discuss &lt;em&gt;categories&lt;/em&gt; of data types and one of the main categories is Python’s &lt;strong&gt;sequence&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn about:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Basic &lt;strong&gt;characteristics of a sequence&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operations&lt;/strong&gt; that are &lt;strong&gt;common to most sequences&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Special methods&lt;/strong&gt; associated with sequences&lt;/li&gt;
&lt;li&gt;Abstract base classes &lt;strong&gt;&lt;code&gt;Sequence&lt;/code&gt; and &lt;code&gt;MutableSequence&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;User-defined mutable and immutable sequences&lt;/strong&gt; and how to create them&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This tutorial assumes that you’re familiar with &lt;a href=&quot;https://realpython.com/python-data-types/&quot;&gt;Python’s built-in data types&lt;/a&gt; and with the &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;basics of object-oriented programming&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Get Your Code:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-sequences-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-sequences-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 Python sequences in this comprehensive guide.&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.654fd44c148d.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 Sequences: A Comprehensive Guide” 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-sequences/&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: #e5c5ac;&quot; alt=&quot;Python Sequences: A Comprehensive Guide&quot; src=&quot;https://files.realpython.com/media/Python-Sequences_Watermarked.988c75bb60be.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-Sequences_Watermarked.988c75bb60be.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-Sequences_Watermarked.988c75bb60be.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-Sequences_Watermarked.988c75bb60be.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-Sequences_Watermarked.988c75bb60be.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.654fd44c148d.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-sequences/&quot; class=&quot;stretched-link&quot;&gt;&lt;span class=&quot;my-0 h4&quot;&gt;Python Sequences: A Comprehensive Guide&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 sequences in Python. You&#x27;ll revisit the basic characteristics of a sequence, operations common to most sequences, special methods associated with sequences, and how to create user-defined mutable and immutable sequences.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;h2 id=&quot;building-blocks-of-python-sequences&quot;&gt;Building Blocks of Python Sequences&lt;a class=&quot;headerlink&quot; href=&quot;#building-blocks-of-python-sequences&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It’s likely you used a Python sequence the last time you wrote Python code, even if you don’t know it. The term &lt;em&gt;sequence&lt;/em&gt; doesn’t refer to a specific data type but to a category of data types that share common characteristics.&lt;/p&gt;
&lt;h3 id=&quot;characteristics-of-python-sequences&quot;&gt;Characteristics of Python Sequences&lt;a class=&quot;headerlink&quot; href=&quot;#characteristics-of-python-sequences&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;a href=&quot;https://docs.python.org/3/glossary.html#term-sequence&quot;&gt;sequence&lt;/a&gt; is a data structure that contains items arranged in order, and you can access each item using an integer index that represents its position in the sequence. You can always find the length of a sequence. Here are some examples of sequences from Python’s basic built-in data types:&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.654fd44c148d.svg#regular--rectangle-terminal&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/span&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# List&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;countries&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;USA&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Canada&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;UK&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Norway&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Malta&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;India&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;country&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;countries&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;country&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;USA&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Canada&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;UK&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Norway&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Malta&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;India&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;n&quot;&gt;countries&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;6&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;countries&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;USA&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Tuple&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;countries&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;USA&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Canada&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;UK&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Norway&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Malta&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;India&quot;&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;country&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;countries&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;country&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;USA&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Canada&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;UK&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Norway&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;Malta&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;India&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;n&quot;&gt;countries&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;6&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;countries&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;USA&#x27;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Strings&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;country&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;India&quot;&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;letter&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;country&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;letter&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;I&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;n&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;d&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;i&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;a&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;n&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&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;country&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;&#x27;I&#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.654fd44c148d.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.654fd44c148d.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;Lists, tuples, and strings are among Python’s most basic data types. Even though they’re different types with distinct characteristics, they have some common traits. You can summarize the characteristics that define a Python sequence as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A sequence is an &lt;a href=&quot;https://realpython.com/python-iterators-iterables/&quot;&gt;iterable&lt;/a&gt;, which means you can iterate through it.&lt;/li&gt;
&lt;li&gt;A sequence has a length, which means you can pass it to &lt;a href=&quot;https://realpython.com/len-python-function/&quot;&gt;&lt;code&gt;len()&lt;/code&gt;&lt;/a&gt; to get its number of elements.&lt;/li&gt;
&lt;li&gt;An element of a sequence can be accessed based on its position in the sequence using an integer index. You can use the square bracket notation to index a sequence.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are other built-in data types in Python that also have all of these characteristics. One of these is the &lt;a href=&quot;https://realpython.com/python-range/&quot;&gt;&lt;code&gt;range&lt;/code&gt; object&lt;/a&gt;:&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.654fd44c148d.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;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type&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;go&quot;&gt;&amp;lt;class &#x27;range&#x27;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;6&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;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;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;10&lt;/span&gt;

&lt;span class=&quot;gp&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;... &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;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;6&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;7&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;9&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can iterate through a &lt;code&gt;range&lt;/code&gt; object, which makes it iterable. You can also find its length using &lt;code&gt;len()&lt;/code&gt; and fetch items through indexing. Therefore, a &lt;code&gt;range&lt;/code&gt; object is also a sequence.&lt;/p&gt;
&lt;p&gt;You can also verify that &lt;a href=&quot;https://realpython.com/python-mutable-vs-immutable-types/&quot;&gt;&lt;code&gt;bytes&lt;/code&gt; and &lt;code&gt;bytearray&lt;/code&gt; objects&lt;/a&gt;, two of Python’s built-in data structures, are also sequences. Both are sequences of integers. A &lt;code&gt;bytes&lt;/code&gt; sequence is immutable, while a &lt;code&gt;bytearray&lt;/code&gt; is mutable.&lt;/p&gt;
&lt;h3 id=&quot;special-methods-associated-with-python-sequences&quot;&gt;Special Methods Associated With Python Sequences&lt;a class=&quot;headerlink&quot; href=&quot;#special-methods-associated-with-python-sequences&quot; title=&quot;Permanent link&quot;&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;In Python, the key characteristics of a data type are determined using &lt;a href=&quot;https://realpython.com/python-magic-methods/&quot;&gt;special methods&lt;/a&gt;, which are defined in the class definitions. The special methods associated with the properties of sequences are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;.__iter__()&lt;/code&gt;&lt;/strong&gt;: This special method makes an object iterable using Python’s preferred iteration protocol. However, it’s possible for a class without an &lt;code&gt;.__iter__()&lt;/code&gt; special method to create iterable objects if the class has a &lt;code&gt;.__getitem__()&lt;/code&gt; special method that supports iteration. Most sequences have an &lt;code&gt;.__iter__()&lt;/code&gt; special method, but it’s possible to have a sequence without this method.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;.__len__()&lt;/code&gt;&lt;/strong&gt;: This special method defines the length of an object, which is normally the number of elements contained within it. The &lt;code&gt;len()&lt;/code&gt; built-in function calls an object’s &lt;code&gt;.__len__()&lt;/code&gt; special method. Every sequence has this special method.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;.__getitem__()&lt;/code&gt;&lt;/strong&gt;: This special method enables you to access an item from a sequence. The square brackets notation can be used to fetch an item. The expression &lt;code&gt;countries[0]&lt;/code&gt; is equivalent to &lt;code&gt;countries.__getitem__(0)&lt;/code&gt;. For sequences, &lt;code&gt;.__getitem__()&lt;/code&gt; should accept integer arguments starting from zero. Every sequence has this special method. This method can also ensure an object is iterable if the &lt;code&gt;.__iter__()&lt;/code&gt; special method is missing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Therefore, all sequences have a &lt;code&gt;.__len__()&lt;/code&gt; and a &lt;code&gt;.__getitem__()&lt;/code&gt; special method and most also have &lt;code&gt;.__iter__()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;However, it’s not sufficient for an object to have these special methods to be a sequence. For example, many mappings also have these three methods but mappings aren’t sequences.&lt;/p&gt;
&lt;p&gt;A dictionary is an example of a mapping. You can find the length of a dictionary and iterate through its keys using a &lt;code&gt;for&lt;/code&gt; loop or other iteration techniques. You can also fetch an item from a dictionary using the square brackets notation.&lt;/p&gt;
&lt;p&gt;This characteristic is defined by &lt;code&gt;.__getitem__()&lt;/code&gt;. However, &lt;code&gt;.__getitem__()&lt;/code&gt; needs arguments that are dictionary keys and returns their matching values. You can’t index a dictionary using integers that refer to an item’s position in the dictionary. Therefore, dictionaries are not sequences.&lt;/p&gt;
&lt;h2 id=&quot;slicing-in-python-sequences&quot;&gt;Slicing in Python Sequences&lt;a class=&quot;headerlink&quot; href=&quot;#slicing-in-python-sequences&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-sequences/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/python-sequences/ »&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>Working With Global Variables in Python Functions</title>
      <id>https://realpython.com/courses/global-variables-in-python-functions/</id>
      <link href="https://realpython.com/courses/global-variables-in-python-functions/"/>
      <updated>2024-04-30T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to use global variables in Python functions using the global keyword or the built-in globals() function. You&#x27;ll also learn a few strategies to avoid relying on global variables because they can lead to code that&#x27;s difficult to understand, debug, and maintain.</summary>
      <content type="html">
        &lt;p&gt;A &lt;strong&gt;global variable&lt;/strong&gt; is a variable that you can use from any part of a program, including within &lt;strong&gt;functions&lt;/strong&gt;. Using global variables inside your Python functions can be tricky. You&amp;rsquo;ll need to differentiate between accessing and changing the values of the target global variable if you want your code to work correctly.&lt;/p&gt;
&lt;p&gt;Global variables can play a fundamental role in many software projects because they enable data sharing across an entire program. However, you should use them judiciously to avoid issues.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Understand &lt;strong&gt;global variables&lt;/strong&gt; and how they work in Python&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access&lt;/strong&gt; global variables within your Python functions directly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modify&lt;/strong&gt; and &lt;strong&gt;create&lt;/strong&gt; global variables within functions using the &lt;strong&gt;&lt;code&gt;global&lt;/code&gt; keyword&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Access&lt;/strong&gt;, &lt;strong&gt;create&lt;/strong&gt;, and &lt;strong&gt;modify&lt;/strong&gt; global variables within your functions with the &lt;strong&gt;&lt;code&gt;globals()&lt;/code&gt; function&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Explore strategies to &lt;strong&gt;avoid using global variables&lt;/strong&gt; in Python code&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python&#x27;s unittest: Writing Unit Tests for Your Code</title>
      <id>https://realpython.com/python-unittest/</id>
      <link href="https://realpython.com/python-unittest/"/>
      <updated>2024-04-29T14:00:00+00:00</updated>
      <summary>In this tutorial, you&#x27;ll learn how to use the unittest framework to create unit tests for your Python code. Along the way, you&#x27;ll also learn how to create test cases, fixtures, test suites, and more.</summary>
      <content type="html">
        &lt;div&gt;&lt;p&gt;The Python &lt;a href=&quot;https://docs.python.org/3/library/index.html&quot;&gt;standard library&lt;/a&gt; ships with a testing framework named &lt;strong&gt;&lt;code&gt;unittest&lt;/code&gt;&lt;/strong&gt;, which you can use to write automated tests for your code. The &lt;code&gt;unittest&lt;/code&gt; package has an object-oriented approach where test cases derive from a base class, which has several useful methods.&lt;/p&gt;
&lt;p&gt;The framework supports many features that will help you write consistent unit tests for your code. These features include test cases, fixtures, test suites, and test discovery capabilities.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Write &lt;code&gt;unittest&lt;/code&gt; tests with the &lt;strong&gt;&lt;code&gt;TestCase&lt;/code&gt;&lt;/strong&gt; class&lt;/li&gt;
&lt;li&gt;Explore the &lt;strong&gt;assert&lt;/strong&gt; methods that &lt;code&gt;TestCase&lt;/code&gt; provides&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;unittest&lt;/code&gt; from the &lt;strong&gt;command line&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Group test cases using the &lt;strong&gt;&lt;code&gt;TestSuite&lt;/code&gt;&lt;/strong&gt; class&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;fixtures&lt;/strong&gt; to handle &lt;strong&gt;setup&lt;/strong&gt; and &lt;strong&gt;teardown&lt;/strong&gt; logic&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get the most out of this tutorial, you should be familiar with some important Python concepts, such as &lt;a href=&quot;https://realpython.com/python3-object-oriented-programming/&quot;&gt;object-oriented programming&lt;/a&gt;, &lt;a href=&quot;https://realpython.com/inheritance-composition-python/&quot;&gt;inheritance&lt;/a&gt;, and &lt;a href=&quot;https://realpython.com/python-assert-statement/&quot;&gt;assertions&lt;/a&gt;. Having a good understanding of code &lt;a href=&quot;https://realpython.com/python-testing/&quot;&gt;testing&lt;/a&gt; is a plus.&lt;/p&gt;
&lt;div class=&quot;alert alert-warning&quot; role=&quot;alert&quot;&gt;
&lt;p&gt;&lt;strong markdown=&quot;1&quot;&gt;Free Bonus:&lt;/strong&gt; &lt;a href=&quot;https://realpython.com/bonus/python-unittest-code/&quot; class=&quot;alert-link&quot; data-toggle=&quot;modal&quot; data-target=&quot;#modal-python-unittest-code&quot; data-focus=&quot;false&quot; markdown=&quot;1&quot;&gt;Click here to download the free sample code&lt;/a&gt; that shows you how to use Python’s unittest to write tests for your code.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container border rounded text-wrap-pretty my-3&quot;&gt;

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

  &lt;hr&gt;

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

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

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


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

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

&lt;/div&gt;

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

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

  &lt;hr&gt;

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

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

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


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

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

&lt;/div&gt;

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

&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(3)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(5)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(15)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(4)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    4&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(30)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(9)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;fizz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(10)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &#x27;buzz&#x27;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;gt;&amp;gt;&amp;gt; fizzbuzz(2)&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    2&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz buzz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fizz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;buzz&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To use these &lt;code&gt;doctest&lt;/code&gt; tests, you’ll need to include them in the docstring of your function as shown above. Then, you can run the tests with the &lt;code&gt;doctest&lt;/code&gt; module by adding the following to your script:&lt;/p&gt;
&lt;div class=&quot;codeblock mb-3 w-100&quot; aria-label=&quot;Code block&quot; data-syntax-language=&quot;python&quot;&gt;
  &lt;div class=&quot;codeblock__header d-flex justify-content-between codeblock--blue&quot;&gt;
    &lt;span class=&quot;mr-2 noselect&quot; aria-label=&quot;Language&quot;&gt;Python&lt;/span&gt;
    
    &lt;div class=&quot;noselect&quot;&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div style=&quot;position: relative;&quot;&gt;
    &lt;div class=&quot;highlight highlight--with-header&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;vm&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;__main__&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;doctest&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;doctest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testmod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
    
    &lt;button class=&quot;codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only&quot; title=&quot;Copy to clipboard&quot;&gt;&lt;span class=&quot;icon baseline&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg aria-hidden=&quot;true&quot;&gt;&lt;use href=&quot;/static/icons.654fd44c148d.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.654fd44c148d.svg#@check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;Copied!&lt;/span&gt;
    &lt;/template&gt;
    
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This code will automatically run the tests defined in the docstrings when you execute the Python file. Remember, the corrected order of conditions in the function ensures that numbers divisible by both &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt; return &lt;code&gt;&quot;fizz buzz&quot;&lt;/code&gt;, which is crucial for the FizzBuzz logic.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Wow! That great! The chat not only wrote the &lt;code&gt;doctest&lt;/code&gt; tests for you. It also fixed the issue, explained important concepts around &lt;code&gt;doctest&lt;/code&gt;, and provided instructions on how to run the tests. Note that the tests cover both regular and edge cases, which is pretty convenient.&lt;/p&gt;
&lt;/div&gt;&lt;h2&gt;&lt;a href=&quot;https://realpython.com/chatgpt-unit-tests-python/?utm_source=realpython&amp;utm_medium=rss&quot;&gt;Read the full article at https://realpython.com/chatgpt-unit-tests-python/ »&lt;/a&gt;&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #201: Decoupling Systems to Get Closer to the Data</title>
      <id>https://realpython.com/podcasts/rpp/201/</id>
      <link href="https://realpython.com/podcasts/rpp/201/"/>
      <updated>2024-04-19T12:00:00+00:00</updated>
      <summary>What are the benefits of using a decoupled data processing system? How do you write reusable queries for a variety of backend data platforms? This week on the show, Phillip Cloud, the lead maintainer of Ibis, will discuss this portable Python dataframe library.</summary>
      <content type="html">
        &lt;p&gt;What are the benefits of using a decoupled data processing system? How do you write reusable queries for a variety of backend data platforms? This week on the show, Phillip Cloud, the lead maintainer of Ibis, will discuss this portable Python dataframe library.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Python&#x27;s unittest: Writing Unit Tests for Your Code</title>
      <id>https://realpython.com/quizzes/python-unittest/</id>
      <link href="https://realpython.com/quizzes/python-unittest/"/>
      <updated>2024-04-19T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python testing with the unittest framework from the standard library. With this knowledge, you&#x27;ll be able to create basic tests, execute them, and find bugs before your users do.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of testing your Python code with the &lt;a href=&quot;https://realpython.com/python-unittest/&quot;&gt;unittest framework&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Testing in Python is a huge topic and can come with a lot of complexity, but it doesn&amp;rsquo;t need to be hard. You can create simple tests for your application in a few easy steps and then build on them from there.&lt;/p&gt;
&lt;p&gt;With this quiz, you can check your understanding of testing with Python&amp;rsquo;s &lt;code&gt;unittest&lt;/code&gt; framework. Good luck!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Using raise for Effective Exceptions</title>
      <id>https://realpython.com/courses/using-raise-for-effective-exceptions/</id>
      <link href="https://realpython.com/courses/using-raise-for-effective-exceptions/"/>
      <updated>2024-04-16T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to raise exceptions in Python, which will improve your ability to efficiently handle errors and exceptional situations in your code. This way, you&#x27;ll write more reliable, robust, and maintainable code.</summary>
      <content type="html">
        &lt;p&gt;In your Python journey, you&amp;rsquo;ll come across situations where you need to signal that something is going wrong in your code. For example, maybe a file doesn&amp;rsquo;t exist, a network or database connection fails, or your code gets invalid input. A common approach to tackle these issues is to &lt;strong&gt;raise an exception&lt;/strong&gt;, notifying the user that an error has occurred. That&amp;rsquo;s what Python&amp;rsquo;s &lt;code&gt;raise&lt;/code&gt; statement is for.&lt;/p&gt;
&lt;p&gt;Learning about the &lt;code&gt;raise&lt;/code&gt; statement allows you to effectively handle errors and exceptional situations in your code. This way, you&amp;rsquo;ll develop more robust programs and higher-quality code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Raise exceptions in Python using the &lt;strong&gt;&lt;code&gt;raise&lt;/code&gt;&lt;/strong&gt; statement&lt;/li&gt;
&lt;li&gt;Decide &lt;strong&gt;which exceptions&lt;/strong&gt; to raise and &lt;strong&gt;when&lt;/strong&gt; to raise them in your code&lt;/li&gt;
&lt;li&gt;Explore common &lt;strong&gt;use cases&lt;/strong&gt; for raising exceptions in Python&lt;/li&gt;
&lt;li&gt;Apply &lt;strong&gt;best practices&lt;/strong&gt; for raising exceptions in your Python code&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Write Pythonic and Clean Code With namedtuple</title>
      <id>https://realpython.com/quizzes/python-namedtuple/</id>
      <link href="https://realpython.com/quizzes/python-namedtuple/"/>
      <updated>2024-04-15T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of Python&#x27;s namedtuple() function from the collections module. This function allows you to create immutable sequence types that you can access using descriptive field names and dot notation.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/python-namedtuple/&quot;&gt;Python&amp;rsquo;s &lt;code&gt;namedtuple()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to create &lt;code&gt;namedtuple&lt;/code&gt; classes, identify and take advantage of the cool features of &lt;code&gt;namedtuple&lt;/code&gt;, use &lt;code&gt;namedtuple&lt;/code&gt; instances to write Pythonic code, and decide when to use a &lt;code&gt;namedtuple&lt;/code&gt; over a similar data structure.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #200: Avoiding Error Culture and Getting Help Inside Python</title>
      <id>https://realpython.com/podcasts/rpp/200/</id>
      <link href="https://realpython.com/podcasts/rpp/200/"/>
      <updated>2024-04-12T12:00:00+00:00</updated>
      <summary>What is error culture, and how do you avoid it within your organization? How do you navigate alert and notification fatigue? Hey, it&#x27;s episode #200! Real Python&#x27;s editor-in-chief, Dan Bader, joins us this week to celebrate. Christopher Trudeau also returns to bring another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What is error culture, and how do you avoid it within your organization? How do you navigate alert and notification fatigue? Hey, it&#x27;s episode #200! Real Python&#x27;s editor-in-chief, Dan Bader, joins us this week to celebrate. Christopher Trudeau also returns to bring another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Format Floats Within F-Strings</title>
      <id>https://realpython.com/quizzes/format-floats-within-f-strings/</id>
      <link href="https://realpython.com/quizzes/format-floats-within-f-strings/"/>
      <updated>2024-04-12T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of how to format floats within f-strings in Python. This knowledge will let you control the precision and appearance of floating-point numbers when you incorporate them into formatted strings.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/how-to-python-f-string-format-float/&quot;&gt;How to Format Floats Within F-Strings in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll often need to format and round a Python &lt;code&gt;float&lt;/code&gt; to display the results of your calculations neatly within strings. While there are several ways to format numbers in Python, formatted string literals or &lt;a href=&quot;https://realpython.com/python-f-strings/&quot;&gt;f-strings&lt;/a&gt; are usually the most frequent choice in modern Python programs. Knowing how to use f-strings effectively can make your code more readable and concise.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: What&#x27;s Lazy Evaluation in Python?</title>
      <id>https://realpython.com/quizzes/python-lazy-evaluation/</id>
      <link href="https://realpython.com/quizzes/python-lazy-evaluation/"/>
      <updated>2024-04-12T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of the differences between lazy and eager evaluation in Python. By working through this quiz, you&#x27;ll revisit how Python optimizes memory use and computational overhead by deciding when to compute values.</summary>
      <content type="html">
        &lt;p&gt;Lazy evaluation is a programming concept where the evaluation of an expression is deferred until its value is actually needed. This can lead to performance enhancements by avoiding unnecessary calculations, and it can also allow for the creation of potentially infinite data structures. As you embark on this quiz, you&amp;rsquo;ll test your knowledge of lazy evaluation in Python and learn how to apply this concept to write cleaner and more efficient code.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Generating QR Codes With Python</title>
      <id>https://realpython.com/courses/generating-qr-codes/</id>
      <link href="https://realpython.com/courses/generating-qr-codes/"/>
      <updated>2024-04-09T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to use Python to generate QR codes, from your standard black-and-white QR codes to beautiful ones with your favorite colors. You&#x27;ll learn how to format QR codes, rotate them, and even replace the static background with moving images.</summary>
      <content type="html">
        &lt;p&gt;From restaurant e-menus to airline boarding passes, &lt;strong&gt;QR codes&lt;/strong&gt; have numerous applications that impact your day-to-day life and enrich the user&amp;rsquo;s experience. Wouldn&amp;rsquo;t it be great to make them look good, too? With the help of this video course, you&amp;rsquo;ll learn how to use Python to generate beautiful QR codes for your personal use case. &lt;/p&gt;
&lt;p&gt;In its most basic format, a QR code contains black squares and dots on a white background, with information that any smartphone or device with a dedicated QR scanner can decode. Unlike a traditional bar code, which holds information horizontally, a QR code holds the data in two dimensions, and it can hold over a hundred times more information.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Generate&lt;/strong&gt; a basic black-and-white QR code&lt;/li&gt;
&lt;li&gt;Change the &lt;strong&gt;size&lt;/strong&gt; and &lt;strong&gt;margins&lt;/strong&gt; of the QR code&lt;/li&gt;
&lt;li&gt;Create &lt;strong&gt;colorful&lt;/strong&gt; QR codes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rotate&lt;/strong&gt; the QR code&lt;/li&gt;
&lt;li&gt;Replace the static background with an &lt;strong&gt;animated GIF&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #199: Leveraging Documents and Data to Create a Custom LLM Chatbot</title>
      <id>https://realpython.com/podcasts/rpp/199/</id>
      <link href="https://realpython.com/podcasts/rpp/199/"/>
      <updated>2024-04-05T12:00:00+00:00</updated>
      <summary>How do you customize a LLM chatbot to address a collection of documents and data? What tools and techniques can you use to build embeddings into a vector database? This week on the show, Calvin Hendryx-Parker is back to discuss developing an AI-powered, Large Language Model-driven chat interface.</summary>
      <content type="html">
        &lt;p&gt;How do you customize a LLM chatbot to address a collection of documents and data? What tools and techniques can you use to build embeddings into a vector database? This week on the show, Calvin Hendryx-Parker is back to discuss developing an AI-powered, Large Language Model-driven chat interface.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: Build Command-Line Interfaces With Python&#x27;s argparse</title>
      <id>https://realpython.com/quizzes/command-line-interfaces-python-argparse/</id>
      <link href="https://realpython.com/quizzes/command-line-interfaces-python-argparse/"/>
      <updated>2024-04-03T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of creating command-line interfaces (CLIs) in Python using the argparse module. This knowledge is essential for creating user-friendly command-line apps, which are common in development, data science, and systems administration.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/command-line-interfaces-python-argparse/&quot;&gt;Creating Command-line Interfaces in Python with argparse&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Command-line apps may not be common in the general user&amp;rsquo;s space, but they&amp;rsquo;re present in development, data science, systems administration, and many other operations. Every command-line app needs a user-friendly &lt;a href=&quot;https://en.wikipedia.org/wiki/Command-line_interface&quot;&gt;command-line interface (CLI)&lt;/a&gt; so that you can interact with the app itself. In Python, you can create full-featured CLIs with the &lt;code&gt;argparse&lt;/code&gt; module from the standard library.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Python Deep Learning: PyTorch vs Tensorflow</title>
      <id>https://realpython.com/courses/deep-learning-pytorch-tensorflow/</id>
      <link href="https://realpython.com/courses/deep-learning-pytorch-tensorflow/"/>
      <updated>2024-04-02T14:00:00+00:00</updated>
      <summary>PyTorch vs Tensorflow: Which one should you use? Learn about these two popular deep learning libraries and how to choose the best one for your project.</summary>
      <content type="html">
        &lt;p&gt;PyTorch vs TensorFlow: What&amp;rsquo;s the difference? Both are open source Python libraries that use graphs to perform numerical computation on data. Both are used extensively in academic research and commercial code. Both are extended by a variety of APIs, cloud computing platforms, and model repositories.&lt;/p&gt;
&lt;p&gt;If they&amp;rsquo;re so similar, then which one is best for your project?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What the differences are between &lt;strong&gt;PyTorch&lt;/strong&gt; and &lt;strong&gt;TensorFlow&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;What &lt;strong&gt;tools&lt;/strong&gt; and &lt;strong&gt;resources&lt;/strong&gt; are available for each&lt;/li&gt;
&lt;li&gt;How to choose the &lt;strong&gt;best option&lt;/strong&gt; for your specific use case&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You&amp;rsquo;ll start by taking a close look at both platforms, beginning with the slightly older TensorFlow, before exploring some considerations that can help you determine which choice is best for your project. Let&amp;rsquo;s get started!&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #198: Build a Video Game With Python Turtle &amp; Visualize Data in Seaborn</title>
      <id>https://realpython.com/podcasts/rpp/198/</id>
      <link href="https://realpython.com/podcasts/rpp/198/"/>
      <updated>2024-03-29T12:00:00+00:00</updated>
      <summary>Can you build a Space Invaders clone using Python&#x27;s built-in turtle module? What advantages does the Seaborn data visualization library provide compared to Matplotlib? Christopher Trudeau is back on the show this week, along with special guest Real Python core team member Bartosz Zaczyński. We&#x27;re sharing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;Can you build a Space Invaders clone using Python&#x27;s built-in turtle module? What advantages does the Seaborn data visualization library provide compared to Matplotlib? Christopher Trudeau is back on the show this week, along with special guest Real Python core team member Bartosz Zaczyński. We&#x27;re sharing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Quiz: A Practical Introduction to Web Scraping in Python</title>
      <id>https://realpython.com/quizzes/python-web-scraping-practical-introduction/</id>
      <link href="https://realpython.com/quizzes/python-web-scraping-practical-introduction/"/>
      <updated>2024-03-27T12:00:00+00:00</updated>
      <summary>In this quiz, you&#x27;ll test your understanding of web scraping in Python. Web scraping is a powerful tool for data collection and analysis. By working through this quiz, you&#x27;ll revisit how to parse website data using string methods, regular expressions, and HTML parsers, as well as how to interact with forms and other website components.</summary>
      <content type="html">
        &lt;p&gt;In this quiz, you&amp;rsquo;ll test your understanding of
&lt;a href=&quot;https://realpython.com/python-web-scraping-practical-introduction/&quot;&gt;Web Scraping in Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;By working through this quiz, you&amp;rsquo;ll revisit how to parse website data using string methods and regular expressions, how to parse website data using an HTML parser, and how to interact with forms and other website components.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>Finding Python Easter Eggs</title>
      <id>https://realpython.com/courses/finding-python-easter-eggs/</id>
      <link href="https://realpython.com/courses/finding-python-easter-eggs/"/>
      <updated>2024-03-26T14:00:00+00:00</updated>
      <summary>Python has its fair share of hidden surprises, commonly known as Easter eggs. From clever jokes to secret messages, these little mysteries are often meant to be discovered by curious geeks like you!</summary>
      <content type="html">
        &lt;p&gt;In this &lt;strong&gt;Code Conversation&lt;/strong&gt;, you&amp;rsquo;ll follow a chat between Philipp and Bartosz as they go on an Easter egg hunt. Along the way, you&amp;rsquo;ll:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Learn about Easter egg hunt traditions&lt;/li&gt;
&lt;li&gt;Uncover the first Easter egg in software&lt;/li&gt;
&lt;li&gt;Explore Easter eggs in Python&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There won&amp;rsquo;t be many code examples in this Code Conversation, so you can lean back and join Philipp and Bartosz on their Easter egg hunt.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #197: Using Python in Bioinformatics and the Laboratory</title>
      <id>https://realpython.com/podcasts/rpp/197/</id>
      <link href="https://realpython.com/podcasts/rpp/197/"/>
      <updated>2024-03-22T12:00:00+00:00</updated>
      <summary>How is Python being used to automate processes in the laboratory? How can it speed up scientific work with DNA sequencing? This week on the show, Chemical Engineering PhD Student Parsa Ghadermazi is here to discuss Python in bioinformatics.</summary>
      <content type="html">
        &lt;p&gt;How is Python being used to automate processes in the laboratory? How can it speed up scientific work with DNA sequencing? This week on the show, Chemical Engineering PhD Student Parsa Ghadermazi is here to discuss Python in bioinformatics.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>SQLite and SQLAlchemy in Python: Move Your Data Beyond Flat Files</title>
      <id>https://realpython.com/courses/sqlite-sqlalchemy-python-beyond-flat-files/</id>
      <link href="https://realpython.com/courses/sqlite-sqlalchemy-python-beyond-flat-files/"/>
      <updated>2024-03-19T14:00:00+00:00</updated>
      <summary>In this video course, you&#x27;ll learn how to store and retrieve data using Python, SQLite, and SQLAlchemy as well as with flat files. Using SQLite with Python brings with it the additional benefit of accessing data with SQL. By adding SQLAlchemy, you can work with data in terms of objects and methods.</summary>
      <content type="html">
        &lt;p&gt;All programs process data in one form or another, and many need to be able to save and retrieve that data from one invocation to the next. Python, &lt;a href=&quot;https://www.sqlite.org/index.html&quot;&gt;SQLite&lt;/a&gt;, and &lt;a href=&quot;https://www.sqlalchemy.org/&quot;&gt;SQLAlchemy&lt;/a&gt; give your programs database functionality, allowing you to store data in a single file without the need for a database server.&lt;/p&gt;
&lt;p&gt;You can achieve similar results using &lt;a href=&quot;https://en.wikipedia.org/wiki/Flat-file_database&quot;&gt;flat files&lt;/a&gt; in any number of formats, including CSV, JSON, XML, and even custom formats. Flat files are often human-readable text files&amp;mdash;though they can also be binary data&amp;mdash;with a structure that can be parsed by a computer program. You&amp;rsquo;ll explore using SQL databases and flat files for data storage and manipulation and learn how to decide which approach is right for your program.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In this video course, you&amp;rsquo;ll learn how to use:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Flat files&lt;/strong&gt; for data storage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL&lt;/strong&gt; to improve access to persistent data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQLite&lt;/strong&gt; for data storage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQLAlchemy&lt;/strong&gt; to work with data as Python objects&lt;/li&gt;
&lt;/ul&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  
    <entry>
      <title>The Real Python Podcast – Episode #196: Exploring Duck Typing in Python &amp; Dynamics of Monkey Patching</title>
      <id>https://realpython.com/podcasts/rpp/196/</id>
      <link href="https://realpython.com/podcasts/rpp/196/"/>
      <updated>2024-03-15T12:00:00+00:00</updated>
      <summary>What are the advantages of determining the type of an object by how it behaves? What coding circumstances are not a good fit for duck typing? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.</summary>
      <content type="html">
        &lt;p&gt;What are the advantages of determining the type of an object by how it behaves? What coding circumstances are not a good fit for duck typing? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder&#x27;s Weekly articles and projects.&lt;/p&gt;
        &lt;hr /&gt;
        &lt;p&gt;&lt;em&gt;[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp;amp; sweet Python Trick delivered to your inbox every couple of days. &lt;a href=&quot;https://realpython.com/python-tricks/?utm_source=realpython&amp;amp;utm_medium=rss&amp;amp;utm_campaign=footer&quot;&gt;&amp;gt;&amp;gt; Click here to learn more and see examples&lt;/a&gt; ]&lt;/em&gt;&lt;/p&gt;
      </content>
    </entry>
  

</feed>
