Real Python2026-01-16T12:00:00+00:00https://realpython.com/Real PythonThe Real Python Podcast – Episode #280: Considering Fast and Slow in Python Programminghttps://realpython.com/podcasts/rpp/280/2026-01-16T12:00:00+00:00How often have you heard about the speed of Python? What's actually being measured, where are the bottlenecks---development time or run time---and which matters more for productivity? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.
<p>How often have you heard about the speed of Python? What's actually being measured, where are the bottlenecks---development time or run time---and which matters more for productivity? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
How to Create a Django Projecthttps://realpython.com/django-setup/2026-01-14T14:00:00+00:00Learn how to create a Django project and app in clear, guided steps. Use it as a reference for any future Django project and tutorial you'll work on.
<div><p>Before you can start <a href="https://realpython.com/get-started-with-django-1/">building your Django web application</a>, you need to set up your Django project. In this guide you’ll learn how to create a new Django project in four straightforward steps and only six commands:</p>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Step</th>
<th>Description</th>
<th>Command</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#step-1-prepare-your-environment">1a</a></td>
<td>Set up a virtual environment</td>
<td><code>python -m venv .venv</code></td>
</tr>
<tr>
<td><a href="#step-1-prepare-your-environment">1b</a></td>
<td>Activate the virtual environment</td>
<td><code>source .venv/bin/activate</code></td>
</tr>
<tr>
<td><a href="#step-2-install-django-and-pin-your-dependencies">2a</a></td>
<td>Install Django</td>
<td><code>python -m pip install django</code></td>
</tr>
<tr>
<td><a href="#step-2-install-django-and-pin-your-dependencies">2b</a></td>
<td>Pin your dependencies</td>
<td><code>python -m pip freeze > requirements.txt</code></td>
</tr>
<tr>
<td><a href="#step-3-set-up-a-django-project">3</a></td>
<td>Set up a Django project</td>
<td><code>django-admin startproject <projectname></code></td>
</tr>
<tr>
<td><a href="#step-4-start-a-django-app">4</a></td>
<td>Start a Django app</td>
<td><code>python manage.py startapp <appname></code></td>
</tr>
</tbody>
</table>
</div>
<p>The tutorial focuses on the initial steps you’ll always need to start a new web application.</p>
<p>Use this tutorial as your go-to reference until you’ve built so many projects that the necessary commands become second nature. Until then, follow the steps outlined below and in the <a href="#command-reference-how-to-create-a-django-project">command reference</a>, or download the PDF cheatsheet as a printable reference:</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Free Bonus:</strong> <a href="https://realpython.com/bonus/django-project-cheatsheet/" class="alert-link" data-toggle="modal" data-target="#modal-django-project-cheatsheet" markdown>Click here to download the Django Project cheat sheet</a> that assembles all important commands and tips on one page that’s easy to print.</p>
</div>
<p>There are also a few exercises throughout the tutorial to help reinforce what you’re learning, and you can test your knowledge in the associated quiz:</p>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “How to Create a Django Project” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/django-setup/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #abe0e6;" alt="Django Setup Guide" src="https://files.realpython.com/media/Django_Setup_Watermark.6c4def7c5b2f.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Django_Setup_Watermark.6c4def7c5b2f.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Django_Setup_Watermark.6c4def7c5b2f.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Django_Setup_Watermark.6c4def7c5b2f.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Django_Setup_Watermark.6c4def7c5b2f.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/django-setup/" class="stretched-link"><span class="my-0 h4">How to Create a Django Project</span></a>
<p class="text-muted mb-0 small">Check your Django setup skills. Install safely and pin requirements, create a project and an app. Start building your first site.</p>
</div>
</div>
</div>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/django-setup-code/" class="alert-link" data-toggle="modal" data-target="#modal-django-setup-code" markdown>Click here to download the free sample code</a> that shows you how to create a Django project.</p>
</div>
<h2 id="prerequisites">Prerequisites<a class="headerlink" href="#prerequisites" title="Permanent link"></a></h2>
<p>Before you start creating your <a href="https://www.djangoproject.com/">Django</a> project, make sure you have the right tools and knowledge in place. This tutorial assumes you’re comfortable working with the <a href="/ref/glossary/console/" class="ref-link">command line</a>, but you don’t need to be an expert. Here’s what you’ll need to get started:</p>
<ul>
<li><a href="https://realpython.com/installing-python/">Python 3.12 or higher installed</a> on your system</li>
<li>Basic familiarity with <a href="https://realpython.com/python-virtual-environments-a-primer/">virtual environments</a></li>
<li>Understanding of Python’s package manager, <a href="https://realpython.com/what-is-pip/"><code>pip</code></a></li>
<li>Access to a <a href="https://realpython.com/terminal-commands/">command-line interface</a></li>
</ul>
<p>You don’t need any prior Django experience to complete this guide. However, to build functionality beyond the basic scaffolding, you’ll need to know <a href="https://realpython.com/products/python-basics-book/">Python basics</a> and at least some <a href="https://realpython.com/learning-paths/django-web-development/">Django</a>.</p>
<h2 id="step-1-prepare-your-environment">Step 1: Prepare Your Environment<a class="headerlink" href="#step-1-prepare-your-environment" title="Permanent link"></a></h2>
<p>When you’re ready to start your new Django web application, create a new folder and navigate into it. In this folder, you’ll set up a new <a href="/ref/glossary/virtual-environment/" class="ref-link">virtual environment</a> using your <a href="/ref/glossary/console/" class="ref-link">terminal</a>:</p>
<ul class="nav nav-tabs justify-content-end js-platform-widget-tabs" role="tablist">
<li class="nav-item mb-0 js-platform-widget-tab-windows" role="presentation">
<a class="nav-link link-unstyled text-body active small" id="windows-tab-1" data-toggle="tab" href="#windows-1" role="tab" aria-controls="windows-1" aria-selected="true"><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#brands--windows"></use></svg></span>Windows</a>
</li>
<li class="nav-item mb-0 js-platform-widget-tab-linuxmacos" role="presentation">
<a class="nav-link link-unstyled text-body small" id="macos-tab-1" data-toggle="tab" href="#linux-macos-1" role="tab" aria-controls="linux-macos-1" aria-selected="false"><span class="icon baseline text-muted" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#v4--linux"></use></svg></span><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#v4--apple"></use></svg></span>Linux + macOS</a>
</li>
</ul>
<div class="tab-content mt-2 mb-0 js-platform-widget-content">
<div aria-labelledby="windows-tab-1" class="tab-pane fade show active" id="windows-1" role="tabpanel">
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">PS> </span><span class="n">python</span> <span class="n">-m</span> <span class="n">venv</span> <span class="p">.</span><span class="n">venv</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
</div>
<div aria-labelledby="linux-macos-tab-1" class="tab-pane fade " id="linux-macos-1" role="tabpanel">
<code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Shell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>python3<span class="w"> </span>-m<span class="w"> </span>venv<span class="w"> </span>.venv
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
</div>
</div>
<p>This command sets up a new virtual environment named <code>.venv</code> in your current working directory. Once the process is complete, you also need to activate the virtual environment:</p>
<ul class="nav nav-tabs justify-content-end js-platform-widget-tabs" role="tablist">
<li class="nav-item mb-0 js-platform-widget-tab-windows" role="presentation">
<a class="nav-link link-unstyled text-body active small" id="windows-tab-2" data-toggle="tab" href="#windows-2" role="tab" aria-controls="windows-2" aria-selected="true"><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#brands--windows"></use></svg></span>Windows</a>
</li>
<li class="nav-item mb-0 js-platform-widget-tab-linuxmacos" role="presentation">
<a class="nav-link link-unstyled text-body small" id="macos-tab-2" data-toggle="tab" href="#linux-macos-2" role="tab" aria-controls="linux-macos-2" aria-selected="false"><span class="icon baseline text-muted" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#v4--linux"></use></svg></span><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#v4--apple"></use></svg></span>Linux + macOS</a>
</li>
</ul>
<div class="tab-content mt-2 mb-0 js-platform-widget-content">
<div aria-labelledby="windows-tab-2" class="tab-pane fade show active" id="windows-2" role="tabpanel">
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">PS> </span><span class="p">.</span><span class="n">venv</span><span class="p">\</span><span class="n">Scripts</span><span class="p">\</span><span class="n">activate</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
</div>
<div aria-labelledby="linux-macos-tab-2" class="tab-pane fade " id="linux-macos-2" role="tabpanel">
<code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Shell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span><span class="nb">source</span><span class="w"> </span>.venv/bin/activate
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
</div>
</div>
<p>If the activation was successful, then you’ll see the name of your virtual environment, <code>(.venv)</code>, at the beginning of your command prompt. This means that your environment setup is complete.</p>
<p>You can learn more about how to <a href="https://realpython.com/python-virtual-environments-a-primer/">work with virtual environments in Python</a>, and how to <a href="https://realpython.com/learning-paths/perfect-your-python-development-setup/">perfect your Python development setup</a>, but for your Django setup, you have all you need. You can continue with installing the <code>django</code> package.</p>
<h2 id="step-2-install-django-and-pin-your-dependencies">Step 2: Install Django and Pin Your Dependencies<a class="headerlink" href="#step-2-install-django-and-pin-your-dependencies" title="Permanent link"></a></h2>
</div><h2><a href="https://realpython.com/django-setup/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/django-setup/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: How to Create a Django Projecthttps://realpython.com/quizzes/django-setup/2026-01-14T12:00:00+00:00Check your Django setup skills. Install safely and pin requirements, create a project and an app. Start building your first site.
<p>In this quiz, you’ll test your understanding of
<a href="https://realpython.com/django-setup/">creating a Django project</a>.</p>
<p>By working through this quiz, you’ll revisit how to create and activate a virtual environment, install Django and pin your dependencies, start a Django project, and start a Django app. You will also see how isolating dependencies helps others reproduce your setup.</p>
<p>To revisit and keep learning, watch the video course on
<a href="https://realpython.com/courses/set-up-django-project/">How to Set Up a Django Project</a>.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Intro to Object-Oriented Programming (OOP) in Pythonhttps://realpython.com/courses/intro-object-oriented-programming/2026-01-13T14:00:00+00:00Learn Python OOP fundamentals fast: master classes, objects, and constructors with hands-on lessons in this beginner-friendly video course.
<p>Object-oriented programming (OOP) is one of the most significant and essential topics in programming. This course will give you a foundational conceptual understanding of object-oriented programming to help you elevate your Python skills.</p>
<p>You’ll learn how to define custom types using classes and how to instantiate those classes into Python objects that can be used throughout your program.</p>
<p>Finally, you’ll discover how classes can inherit from one another, with a brief introduction to inheritance, enabling you to write maintainable and less redundant Python code.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Python's deque: Implement Efficient Queues and Stackshttps://realpython.com/python-deque/2026-01-12T14:00:00+00:00Use a Python deque to efficiently append and pop elements from both ends of a sequence, build queues and stacks, and set maxlen for history buffers.
<div><p>You can use Python’s <code>deque</code> for efficient appends and pops at both ends of a sequence-like data type. These capabilities are critical when you need to implement queue and stack data structures that operate efficiently even under heavy workloads.</p>
<p>In this tutorial, you’ll learn how <code>deque</code> works, when to use it over a <code>list</code>, and how to apply it in real code.</p>
<p><strong>By the end of this tutorial, you’ll understand that:</strong></p>
<ul>
<li><code>deque</code> internally uses a <strong>doubly linked list</strong>, so end operations are <em>O(1)</em> while random indexing is <em>O(n)</em>.</li>
<li>You can build a <strong>FIFO queue</strong> with <strong><code>.append()</code></strong> and <strong><code>.popleft()</code></strong>, and a <strong>LIFO stack</strong> with <strong><code>.append()</code></strong> and <strong><code>.pop()</code></strong>.</li>
<li><code>deque</code> supports <strong>indexing</strong> but doesn’t support <strong>slicing</strong>.</li>
<li>Passing a value to <strong><code>maxlen</code></strong> creates a bounded deque that <strong>drops items</strong> from the opposite end when full.</li>
<li>In CPython, <strong><code>.append()</code></strong>, <strong><code>.appendleft()</code></strong>, <strong><code>.pop()</code></strong>, <strong><code>.popleft()</code></strong>, and <strong><code>len()</code></strong> are <strong>thread-safe</strong> for multithreaded use.</li>
</ul>
<p>Up next, you’ll get started with <code>deque</code>, benchmark it against <code>list</code>, and explore how it shines in real-world use cases, such as queues, stacks, history buffers, and thread-safe producer-consumer setups.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/python-deque-code/" class="alert-link" data-toggle="modal" data-target="#modal-python-deque-code" markdown>Click here to download the free sample code</a> that shows you how to implement efficient queues and stacks with Python’s deque.</p>
</div>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Python's deque: Implement Efficient Queues and Stacks” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/python-deque/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #b9abe6;" alt="Python's deque: Implement Efficient Queues and Stacks" src="https://files.realpython.com/media/Collections.deque_Watermarked.066fbf353cb4.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Collections.deque_Watermarked.066fbf353cb4.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Collections.deque_Watermarked.066fbf353cb4.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Collections.deque_Watermarked.066fbf353cb4.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Collections.deque_Watermarked.066fbf353cb4.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/python-deque/" class="stretched-link"><span class="my-0 h4">Python's deque: Implement Efficient Queues and Stacks</span></a>
<p class="text-muted mb-0 small">Use Python's deque for fast queues and stacks. Refresh end operations, maxlen rollover, indexing limits, and thread-safe methods.</p>
</div>
</div>
</div>
<h2 id="get-started-with-pythons-deque">Get Started With Python’s <code>deque</code><a class="headerlink" href="#get-started-with-pythons-deque" title="Permanent link"></a></h2>
<p>Appending to and popping from the right end of a Python <a href="https://realpython.com/python-list/"><code>list</code></a> are efficient operations most of the time. Using the <a href="https://en.wikipedia.org/wiki/Big_O_notation">Big <em>O</em> notation</a> for <a href="https://wiki.python.org/moin/TimeComplexity">time complexity</a>, these operations are <em>O(1)</em>. However, when Python needs to reallocate memory to <em>grow</em> the underlying list to accept new items, these operations slow down and can become <em>O</em>(<em>n</em>).</p>
<p>In contrast, appending and popping items from the left end of a Python list are always inefficient and have <em>O</em>(<em>n</em>) time complexity.</p>
<p>Because Python lists provide both operations with the <a href="https://realpython.com/python-append/"><code>.append()</code></a> and <code>.pop()</code> <a href="/ref/glossary/method/" class="ref-link">methods</a>, you can use them as <a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)">stacks</a> and <a href="https://en.wikipedia.org/wiki/Queue_(abstract_data_type)">queues</a>. However, the performance issues you saw before can significantly impact the overall performance of your applications.</p>
<p>Python’s <a href="https://docs.python.org/3/library/collections.html#collections.deque"><code>deque</code></a> was the first data type added to the <a href="https://realpython.com/python-collections-module/"><code>collections</code></a> module back in <a href="https://docs.python.org/3/whatsnew/2.4.html#new-improved-and-deprecated-modules">Python 2.4</a>. This data type was specially designed to overcome the efficiency problems of <code>.append()</code> and <code>.pop()</code> in Python lists.</p>
<p>A deque is a <a href="/ref/glossary/sequence/" class="ref-link">sequence</a>-like <a href="/ref/glossary/data-structure/" class="ref-link">data structure</a> designed as a generalization of <a href="/ref/glossary/stack/" class="ref-link"><strong>stacks</strong></a> and <a href="/ref/glossary/queue/" class="ref-link"><strong>queues</strong></a>. It supports memory-efficient and fast append and pop operations on both ends.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> The word <code>deque</code> is pronounced as “deck.” The name stands for <a href="https://en.wikipedia.org/wiki/Double-ended_queue"><strong>d</strong>ouble-<strong>e</strong>nded <strong>que</strong>ue</a>.</p>
</div>
<p>Append and pop operations on both ends of a <code>deque</code> object are stable and equally efficient because deques are <a href="https://github.com/python/cpython/blob/23acadcc1c75eb74b2459304af70d97a35001b34/Modules/_collectionsmodule.c#L34">implemented</a> as a <a href="https://realpython.com/linked-lists-python/#how-to-use-doubly-linked-lists">doubly linked list</a>. Additionally, append and pop operations on deques are <a href="https://en.wikipedia.org/wiki/Thread_safety">thread-safe</a> and memory-efficient. These features make deques particularly useful for creating custom stacks and queues in Python.</p>
<p>Deques are also a good choice when you need to keep a list of recently seen items, as you can restrict the maximum length of your deque. By setting a maximum length, once a deque is full, it automatically discards items from one end when you append new items to the opposite end.</p>
<p>Here’s a summary of the main features of <code>deque</code>:</p>
<ul>
<li>Stores items of any <a href="https://realpython.com/python-data-types/">data type</a></li>
<li>Is a <a href="/ref/glossary/mutable/" class="ref-link">mutable</a> data type</li>
<li>Supports <a href="https://realpython.com/python-in-operator/">membership operations</a> with the <a href="/ref/keywords/in/" class="ref-link"><code>in</code> operator</a></li>
<li>Supports <a href="/ref/glossary/indexing/" class="ref-link">indexing</a>, like in <code>a_deque[i]</code></li>
<li>Doesn’t support <a href="/ref/glossary/slicing/" class="ref-link">slicing</a>, like in <code>a_deque[0:2]</code></li>
<li>Supports <a href="https://realpython.com/python-built-in-functions/">built-in functions</a> that operate on <a href="https://realpython.com/python-sequences/">sequences</a> and <a href="https://realpython.com/python-iterators-iterables/">iterables</a>, such as <a href="https://realpython.com/len-python-function/"><code>len()</code></a>, <a href="https://realpython.com/python-sort/"><code>sorted()</code></a>, <a href="https://realpython.com/python-reverse-list/"><code>reversed()</code></a>, and more</li>
<li>Doesn’t support <a href="https://en.wikipedia.org/wiki/In-place_algorithm">in-place</a> sorting</li>
<li>Supports normal and reverse <a href="/ref/glossary/iteration/" class="ref-link">iteration</a></li>
<li>Supports pickling with <a href="https://realpython.com/python-pickle-module/"><code>pickle</code></a></li>
<li>Supports fast, memory-efficient, and <a href="https://realpython.com/python-thread-lock/">thread-safe</a> pop and append operations on both ends</li>
</ul>
<p>To create deques, you just need to import <code>deque</code> from <code>collections</code> and call it with an optional <a href="/ref/glossary/iterable/" class="ref-link">iterable</a> as an <a href="/ref/glossary/argument/" class="ref-link">argument</a>:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true">
<div class="codeblock__header codeblock--blue">
<span class="mr-2 noselect" aria-label="Language">Python</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">collections</span><span class="w"> </span><span class="kn">import</span> <span class="n">deque</span>
<span class="gp">>>> </span><span class="c1"># Create an empty deque</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">()</span>
<span class="go">deque([])</span>
<span class="gp">>>> </span><span class="c1"># Use different iterables to create deques</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">((</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="go">deque([1, 2, 3, 4])</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="go">deque([1, 2, 3, 4])</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
<span class="go">deque([1, 2, 3, 4])</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">(</span><span class="s2">"abcd"</span><span class="p">)</span>
<span class="go">deque(['a', 'b', 'c', 'd'])</span>
<span class="gp">>>> </span><span class="n">numbers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"one"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">"two"</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">"three"</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">"four"</span><span class="p">:</span> <span class="mi">4</span><span class="p">}</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">(</span><span class="n">numbers</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="go">deque(['one', 'two', 'three', 'four'])</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">(</span><span class="n">numbers</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="go">deque([1, 2, 3, 4])</span>
<span class="gp">>>> </span><span class="n">deque</span><span class="p">(</span><span class="n">numbers</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="go">deque([('one', 1), ('two', 2), ('three', 3), ('four', 4)])</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>If you instantiate <code>deque</code> without providing an <code>iterable</code> as an argument, then you get an empty deque. If you provide an <code>iterable</code>, then <code>deque</code> initializes the new instance with data from it. The initialization goes from left to right using <code>deque.append()</code>.</p>
<p>The <code>deque</code> initializer takes the following two <a href="https://realpython.com/python-optional-arguments/">optional arguments</a>:</p>
<ol>
<li><strong><code>iterable</code></strong> holds an iterable that provides the initialization data.</li>
<li><strong><code>maxlen</code></strong> holds an integer <a href="https://realpython.com/python-numbers/">number</a> that specifies the maximum length of the deque.</li>
</ol>
<p>As mentioned previously, if you don’t supply an <code>iterable</code>, then you get an empty deque. If you provide a value to <a href="https://docs.python.org/3/library/collections.html#collections.deque.maxlen"><code>maxlen</code></a>, then your deque will only store up to <code>maxlen</code> items.</p>
<p>Finally, you can also use unordered iterables, such as <a href="https://realpython.com/python-sets/">sets</a>, to initialize your deques. In those cases, you won’t have a predefined order for the items in the final deque.</p>
</div><h2><a href="https://realpython.com/python-deque/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-deque/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #279: Coding Python With Confidence: Beginners Live Course Participantshttps://realpython.com/podcasts/rpp/279/2026-01-09T12:00:00+00:00Are you looking for that solid foundation to begin your Python journey? Would the accountability of scheduled group classes help you get through the basics and start building something? This week, two members of the Python for Beginners live course discuss their experiences.
<p>Are you looking for that solid foundation to begin your Python journey? Would the accountability of scheduled group classes help you get through the basics and start building something? This week, two members of the Python for Beginners live course discuss their experiences.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
How to Build a Personal Python Learning Roadmaphttps://realpython.com/build-python-learning-roadmap/2026-01-07T14:00:00+00:00Learn how to create a personalized Python learning roadmap. Set goals, choose resources, and build a plan to track your progress and stay motivated.
<div><p>If you want to learn Python or improve your skills, a detailed plan can help you gauge your current status and navigate toward a target goal. This tutorial will help you craft a personal Python learning roadmap so you can track your progress and stay accountable to your goals and timeline:</p>
<figure class=""><img loading="lazy" class="img-fluid mx-auto d-block border " src="https://files.realpython.com/media/python-learning-roadmap.9959fcebdb42.jpg" width="1329" height="1033" srcset="/cdn-cgi/image/width=332,format=auto/https://files.realpython.com/media/python-learning-roadmap.9959fcebdb42.jpg 332w, /cdn-cgi/image/width=443,format=auto/https://files.realpython.com/media/python-learning-roadmap.9959fcebdb42.jpg 443w, /cdn-cgi/image/width=664,format=auto/https://files.realpython.com/media/python-learning-roadmap.9959fcebdb42.jpg 664w, /cdn-cgi/image/width=1329,format=auto/https://files.realpython.com/media/python-learning-roadmap.9959fcebdb42.jpg 1329w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="A Python Learning Roadmap Sheet that you can fill and print" data-asset="6721"></figure>
<p>The steps in this tutorial are useful for Python developers and learners of all experience levels. While you may be eager to start learning, you might want to set aside an hour or two to outline a plan, especially if you already know your learning goals. If you don’t yet have clear goals, consider spreading that reflection over a few shorter sessions across several days to clarify your direction.</p>
<p>Before you start, gather a few practical tools to support building your plan. This might include a notebook, a calendar or planner (digital or physical), a list of projects or goals you want to work toward, and any Python books or online resources you plan to use.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> If you learn best with structure and accountability, you can also follow your roadmap inside a <a href="https://realpython.com/live/">cohort-based live course</a> delivered by Real Python experts, with weekly live classes and live Q&A.</p>
</div>
<p>You can download a <strong>Personal Python Learning Roadmap</strong> worksheet to help you create your plan by clicking the link below:</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Python Learning Roadmap:</strong> <a href="https://realpython.com/bonus/build-python-learning-roadmap-cheatsheet/" class="alert-link" data-toggle="modal" data-target="#modal-build-python-learning-roadmap-cheatsheet" markdown>Click here to download</a> a free, fillable Python learning roadmap PDF to help you set your aims and track your progress.</p>
</div>
<p>This tutorial will guide you through the planning process, starting with clarifying what you want to achieve and why. From there, you’ll map out the practical steps that will turn your goals into a realistic, actionable roadmap.</p>
<h2 id="step-1-define-your-goals-and-motivation">Step 1: Define Your Goals and Motivation<a class="headerlink" href="#step-1-define-your-goals-and-motivation" title="Permanent link"></a></h2>
<p>To create an effective learning roadmap, you first need to know what you want to achieve and what your motivation is. For this step, you’ll consider the following reflection prompt: </p>
<p><em>What do I want to accomplish with Python, and why?</em></p>
<p>Taking the time to answer this question sets the foundation for every decision you’ll make as you build your roadmap.</p>
<h3 id="define-your-goals">Define Your Goals<a class="headerlink" href="#define-your-goals" title="Permanent link"></a></h3>
<p>Start by deciding <em>what</em> you want to accomplish with Python, then write it down. Research shows that this small step can make a meaningful difference. <a href="https://scholar.dominican.edu/psychology-faculty-conference-presentations/3/?utm_source=scholar.dominican.edu%2Fpsychology-faculty-conference-presentations%2F3&utm_medium=PDF&utm_campaign=PDFCoverPages">In a study</a> conducted by psychology researcher Dr. Gail Matthews at Dominican University of California, participants who wrote down their goals were significantly more likely to achieve them than those who didn’t.</p>
<p>If you’re not sure yet about your goals, here are some questions for you to consider:</p>
<ul>
<li>
<p>Are there specific projects—or types of projects—that you’d like to work on? For example, data analysis, game development, or building a web app.</p>
</li>
<li>
<p>In what context or setting would you like to use your Python skills? For example, at work, in school, or as part of a personal interest or side project.</p>
</li>
</ul>
<p>Remember to write these answers down either in your notebook or on the <strong>Personal Python Learning Roadmap</strong> worksheet included in this tutorial’s downloads. Having them written down will provide helpful context as you continue formulating your roadmap.</p>
<h3 id="determine-your-motivation">Determine Your Motivation<a class="headerlink" href="#determine-your-motivation" title="Permanent link"></a></h3>
<p>Once you have a general goal in mind, think about <em>why</em> you want to achieve it. Your motivation plays a key role in whether you’ll stick with your plan over time.
As clinical psychology professor Dr. Jennifer Crawford <a href="https://hscnews.unm.edu/news/setting-successful-goals">explains</a>:</p>
<blockquote>
<p>If we don’t care about why we’re doing [a goal], then it makes it really difficult to stick with that new behavior.</p>
<p>— <em>Dr. Jennifer Crawford</em></p>
</blockquote>
<p>She also encourages goal-setters to ask how their goals connect with something that’s important to them.</p>
<p>This idea is echoed by psychology professor Angela Duckworth in her book <em>Grit</em>, where she emphasizes that a strong sense of purpose helps you persevere when you encounter obstacles that might otherwise derail your progress.</p>
<p>Some possible reasons behind your “why” might include:</p>
<ul>
<li>A personal interest or a love of learning</li>
<li>A desire to start or advance a career in software development</li>
<li>A goal of earning a computer science degree</li>
<li>An interest in volunteering your skills—for example, creating a Python application that supports a cause you care about</li>
</ul>
<p>As you consider your motivation, see if you can dive deeper into the root of your reasons. A deeper look can add even more meaning and staying power to your goals. For example:</p>
</div><h2><a href="https://realpython.com/build-python-learning-roadmap/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/build-python-learning-roadmap/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Tips for Using the AI Coding Editor Cursorhttps://realpython.com/courses/tips-using-ai-coding-editor-cursor/2026-01-06T14:00:00+00:00Learn Cursor fast: AI powered coding with agents, project aware chat, and inline edits for a VS Code workflow that ships smarter, sooner.
<p>Cursor is an AI-powered integrated development environment (IDE) based on the Visual Studio Code codebase. It comes with a multi-agent interface and the Composer model for fast, agentic coding while keeping a familiar editor workflow with project-aware chat, code completion, and inline edits.</p>
<p>In this course, you will: </p>
<ul>
<li>Understand why Cursor might work for you</li>
<li>Learn how to use different modes & models</li>
<li>See how to run multiple agents at a time</li>
<li>Resolve a tiny merge conflict</li>
<li>Run a project and fix a bug</li>
<li>Learn commands and practice with the terminal</li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Learn From 2025's Most Popular Python Tutorials and Courseshttps://realpython.com/popular-python-tutorials-2025/2026-01-05T14:00:00+00:00Pick from the best Python tutorials and courses of 2025. Revisit core skills, 3.14 updates, AI coding tools, and project walkthroughs. Kickstart your 2026!
<div><p>As we welcome 2026, it’s time to look back on an exciting year for Python. <a href="https://realpython.com/python314-new-features/">Python 3.14</a> arrived with a wave of developer-focused improvements, from lazy annotations that finally resolve long-standing type hinting quirks to clever new t-strings that give you more control over string interpolation.</p>
<p>Meanwhile, 2025 was the year <a href="/ref/ai-coding-tools/" class="ref-link">AI tools</a> truly became part of everyday Python development. From agentic coding with LangGraph to connecting <a href="/ref/ai-coding-glossary/llm/" class="ref-link">LLMs</a> to your data via <a href="/ref/ai-coding-glossary/mcp/" class="ref-link">MCP</a> servers, Python solidified its position as the language of choice for AI-powered workflows.</p>
<p>Here at <a href="https://realpython.com/team/">Real Python</a>, we’re excited to showcase the tutorials and video courses that resonated most with our community throughout 2025. Whether you’re just starting out with Python, leveling up your skills, or diving into advanced topics, this collection has something for you.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Join Now:</strong> <a href="https://realpython.com/bonus/newsletter/" class="alert-link" data-toggle="modal" data-target="#modal-newsletter" markdown>Click here to join the Real Python Newsletter</a> and you’ll never miss another Python tutorial, course, or news update.</p>
</div>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Python Skill Test” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/python-skill-test/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #f2f2f2;" alt="Real Python Quizzes" src="https://files.realpython.com/media/Real-Python-Quizzes-Page_Watermarked.0a38006fcf1a.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Real-Python-Quizzes-Page_Watermarked.0a38006fcf1a.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Real-Python-Quizzes-Page_Watermarked.0a38006fcf1a.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Real-Python-Quizzes-Page_Watermarked.0a38006fcf1a.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Real-Python-Quizzes-Page_Watermarked.0a38006fcf1a.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/python-skill-test/" class="stretched-link"><span class="my-0 h4">Python Skill Test</span></a>
<p class="text-muted mb-0 small">Test your Python knowledge in a skills quiz with basic to advanced questions. Are you a Novice, Intermediate, Proficient, or Expert?</p>
</div>
</div>
</div>
<h2 id="strengthen-your-python-foundations">Strengthen Your Python Foundations<a class="headerlink" href="#strengthen-your-python-foundations" title="Permanent link"></a></h2>
<figure class=""><img loading="lazy" class="img-fluid w-33 float-right ml-3 mt-3 mb-3 rounded" src="https://files.realpython.com/media/Operators-and-Expressions-in-Python_Watermarked.651045da4031.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Operators-and-Expressions-in-Python_Watermarked.651045da4031.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Operators-and-Expressions-in-Python_Watermarked.651045da4031.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Operators-and-Expressions-in-Python_Watermarked.651045da4031.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Operators-and-Expressions-in-Python_Watermarked.651045da4031.jpg 1920w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Operators and Expressions in Python" data-asset="3457"></figure>
<p>If you’re just getting started with Python, <a href="https://realpython.com/learning-paths/python-basics/">building a solid foundation</a> is the best investment you can make. The fundamentals you learn now will support everything you do later, from <a href="https://realpython.com/learning-paths/pandas-data-science/">data analysis</a> to <a href="https://realpython.com/learning-paths/become-python-web-developer/">web development</a> to <a href="https://realpython.com/learning-paths/coding-with-ai/">AI</a>.</p>
<p>These beginner-friendly tutorials and courses help you sharpen the core skills you’ll use every day in Python, including loops, operators, lists, and functional techniques:</p>
<ul>
<li><a href="https://realpython.com/python-join-string/">How to Join Strings in Python</a></li>
<li><a href="https://realpython.com/python-continue/">Skip Ahead in Loops With Python’s continue Keyword</a></li>
<li><a href="https://realpython.com/nested-loops-python/">Nested Loops in Python</a></li>
<li><a href="https://realpython.com/courses/python-operators-expressions/">Python Operators and Expressions</a></li>
<li><a href="https://realpython.com/courses/list-data-type-with-examples/">Exploring Python’s list Data Type With Examples</a></li>
<li><a href="https://realpython.com/courses/using-functional-programming/">Using Functional Programming in Python</a></li>
</ul>
<p>If you’re looking to accelerate your learning with live instruction, then check out our <a href="https://realpython.com/workshops/python-for-beginners/">Python for Beginners Live Course</a>, where you can learn alongside other students and get real-time feedback from experienced instructors.</p>
<p>And don’t forget to grab our downloadable <a href="https://realpython.com/python-cheat-sheet/">Python 3 Cheat Sheet</a> to keep essential syntax and concepts at your fingertips:</p>
<!-- Slim Inline Banner -->
<div class="card my-4 alert alert-warning">
<div class="card-body py-2">
<div class="d-flex align-items-center">
<img src="https://files.realpython.com/media/cheat_sheets_stacked.34027e654084.png" alt="Preview of the Python Cheat Sheet PDF" class="mr-3" style="width:120px;height:auto;flex:0 0 auto;">
<div class="flex-grow-1">
<div class="small mb-2">
<strong>Get Your Free Python Cheat Sheet (PDF):</strong> Learn the basics, fast.
</div>
<form action="/optins/process/" method="post" class="mb-0">
<input type="hidden" name="slug" value="cheat-sheet-slim-inline">
<div class="input-group input-group-sm">
<input name="email" type="email" class="form-control" placeholder="Email address" aria-label="Email address" required>
<div class="input-group-append">
<button name="submit" type="submit" class="btn btn-success">Get »</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<h2 id="explore-whats-new-in-python-314">Explore What’s New in Python 3.14<a class="headerlink" href="#explore-whats-new-in-python-314" title="Permanent link"></a></h2>
<figure class=""><img loading="lazy" class="img-fluid w-33 float-right ml-3 mt-3 mb-3 rounded" src="https://files.realpython.com/media/Python-3.14-Cool-New-Features_Watermarked.1f256aff1d4b.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Python-3.14-Cool-New-Features_Watermarked.1f256aff1d4b.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-3.14-Cool-New-Features_Watermarked.1f256aff1d4b.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-3.14-Cool-New-Features_Watermarked.1f256aff1d4b.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-3.14-Cool-New-Features_Watermarked.1f256aff1d4b.jpg 1920w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Python 3.14: Cool New Features for You to Try" data-asset="6592"></figure>
<p>Python 3.14 brought a collection of thoughtful improvements that make writing and debugging code more enjoyable. The REPL now feels like a proper modern shell, making third-party REPLs like <a href="https://realpython.com/ipython-interactive-python-shell/">IPython</a>, <a href="https://realpython.com/ptpython-shell/">ptpython</a>, and <a href="https://realpython.com/bpython-alternative-python-repl/">bpython</a> less necessary. Type hints behave more intuitively, error messages point you in the right direction faster, and t-strings open up new possibilities for string processing.</p>
<p>These tutorials walk you through the updates you’ll want to start using right away:</p>
<ul>
<li><a href="https://realpython.com/python314-new-features/">Python 3.14: Cool New Features for You to Try</a></li>
<li><a href="https://realpython.com/python-annotations/">Python 3.14: Lazy Annotations</a></li>
<li><a href="https://realpython.com/python-repl-autocompletion-highlighting/">Python 3.14: REPL Autocompletion and Highlighting</a></li>
<li><a href="https://realpython.com/python314-error-messages/">Python 3.14: Better Syntax Error Messages</a></li>
<li><a href="https://realpython.com/python-t-strings/">Python 3.14: Template Strings (T-Strings)</a></li>
</ul>
<p>If you’re curious about any other new features, you can also read the <a href="https://docs.python.org/3.14/whatsnew/3.14.html">3.14 release notes</a>. Staying current with new Python releases helps you write cleaner code and take advantage of performance improvements as they land.</p>
</div><h2><a href="https://realpython.com/popular-python-tutorials-2025/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/popular-python-tutorials-2025/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: How to Properly Indent Python Codehttps://realpython.com/quizzes/how-to-indent-in-python/2026-01-05T12:00:00+00:00Practice proper Python indentation. Take a quiz on using spaces, editor settings, and autoformatting correctly.
<p>In this quiz, you’ll test your understanding of
<a href="https://realpython.com/how-to-indent-in-python/">How to Indent in Python</a>.</p>
<p>By working through this quiz, you’ll revisit how to properly indent Python code, choose helpful editor settings, use spaces properly, apply code formatters, and explain why indentation is required.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: How to Convert Bytes to Strings in Pythonhttps://realpython.com/quizzes/convert-python-bytes-to-strings/2026-01-05T12:00:00+00:00Decode bytes into readable strings in Python. Test your skills working with data from files, APIs, and databases.
<p>In this quiz, you’ll test your understanding of the
<a href="https://realpython.com/convert-python-bytes-to-strings/">Convert Python Bytes to Strings</a> tutorial.</p>
<p>By working through this quiz, you’ll revisit how to decode bytes, choose an encoding, and turn binary data into readable text.</p>
<p>You’ll also see how encodings map byte values to characters so you can handle data from files, databases, and APIs with confidence. For a deeper dive, check out <a href="https://realpython.com/python-encodings-guide/">Python Encodings: A Guide</a> and <a href="https://realpython.com/python-bytes/">Python Bytes</a>.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #278: PyCoder's Weekly 2025 Top Articles & Hidden Gemshttps://realpython.com/podcasts/rpp/278/2026-01-02T12:00:00+00:00PyCoder's Weekly included over 1,500 links to articles, blog posts, tutorials, and projects in 2025. Christopher Trudeau is back on the show this week to help wrap up everything by sharing some highlights and uncovering a few hidden gems from the pile.
<p>PyCoder's Weekly included over 1,500 links to articles, blog posts, tutorials, and projects in 2025. Christopher Trudeau is back on the show this week to help wrap up everything by sharing some highlights and uncovering a few hidden gems from the pile.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
LlamaIndex in Python: A RAG Guide With Exampleshttps://realpython.com/llamaindex-examples/2025-12-24T14:00:00+00:00Learn how to set up LlamaIndex, choose an LLM, load your data, build and persist an index, and run queries to get grounded, reliable answers with examples.
<div><p>Discover how to use LlamaIndex with practical examples. This framework helps you build retrieval-augmented generation (RAG) apps using Python. LlamaIndex lets you load your data and documents, create and persist searchable indexes, and query an LLM using your data as context.</p>
<p>In this tutorial, you’ll learn the basics of installing the package, setting AI providers, spinning up a query engine, and running synchronous or asynchronous queries against remote or local models.</p>
<p><strong>By the end of this tutorial, you’ll understand that:</strong></p>
<ul>
<li>You use <strong>LlamaIndex</strong> to <strong>connect your data to LLMs</strong>, allowing you to <strong>build AI agents</strong>, <strong>workflows</strong>, <strong>query engines</strong>, and <strong>chat engines</strong>.</li>
<li>You can perform <strong>RAG</strong> with LlamaIndex to retrieve relevant context at query time, helping the LLM generate <strong>grounded answers</strong> and <strong>minimize hallucinations</strong>. </li>
</ul>
<p>You’ll start by preparing your environment and installing LlamaIndex. From there, you’ll learn how to load your own files, build and save an index, choose different AI providers, and run targeted queries over your data through a query engine.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/python-llamaindex-examples-code/" class="alert-link" data-toggle="modal" data-target="#modal-python-llamaindex-examples-code" markdown>Click here to download the free sample code</a> that shows you how to use LlamaIndex in Python.</p>
</div>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “LlamaIndex in Python: A RAG Guide With Examples” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/llamaindex-examples/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #e5c6aa;" alt="Python LlamaIndex: Step by Step RAG With Examples" src="https://files.realpython.com/media/LlamaIndex-Example_Watermarked.de4698fa8a9b.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/LlamaIndex-Example_Watermarked.de4698fa8a9b.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/LlamaIndex-Example_Watermarked.de4698fa8a9b.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/LlamaIndex-Example_Watermarked.de4698fa8a9b.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/LlamaIndex-Example_Watermarked.de4698fa8a9b.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/llamaindex-examples/" class="stretched-link"><span class="my-0 h4">LlamaIndex in Python: A RAG Guide With Examples</span></a>
<p class="text-muted mb-0 small">Take this Python LlamaIndex quiz to test your understanding of index persistence, reloading, and performance gains in RAG applications.</p>
</div>
</div>
</div>
<h2 id="start-using-llamaindex">Start Using LlamaIndex<a class="headerlink" href="#start-using-llamaindex" title="Permanent link"></a></h2>
<p><a href="/ref/ai-coding-glossary/training/" class="ref-link">Training</a> or fine-tuning an <a href="/ref/ai-coding-glossary/ai/" class="ref-link">AI</a> model—like a <a href="/ref/ai-coding-glossary/llm/" class="ref-link">large language model (LLM)</a>—on your own data can be a complex and resource-intensive process. Instead of modifying the model itself, you can rely on a pattern called <a href="/ref/ai-coding-glossary/retrieval-augmented-generation/" class="ref-link"><strong>retrieval-augmented generation (RAG)</strong></a>.</p>
<p>RAG is a technique where the system, at query time, first retrieves relevant external documents or data and then passes them to the LLM as additional context. The model uses this context as a source of truth when generating its answer, which typically makes the response more accurate, up to date, and on topic.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> RAG can help reduce hallucinations and prevent models from giving wrong answers. However, recent LLMs are much better at admitting when they don’t know something rather than making up an answer.</p>
</div>
<p>This technique also allows LLMs to provide answers to questions that they wouldn’t have been able to answer otherwise—for example, questions about your internal company information, email history, and similar private data.</p>
<p><a href="https://developers.llamaindex.ai/python/framework/">LlamaIndex</a> is a Python framework that enables you to build AI-powered apps capable of performing RAG. It helps you feed LLMs with your own data through indexing and retrieval tools. Next, you’ll learn the basics of installing, setting up, and using LlamaIndex in your Python projects.</p>
<h3 id="install-and-set-up-llamaindex">Install and Set Up LlamaIndex<a class="headerlink" href="#install-and-set-up-llamaindex" title="Permanent link"></a></h3>
<p>Before installing <a href="/ref/ai-coding-tools/llamaindex/" class="ref-link">LlamaIndex</a>, you should create and activate a Python <a href="/ref/glossary/virtual-environment/" class="ref-link">virtual environment</a>. Refer to <a href="https://realpython.com/python-virtual-environments-a-primer/">Python Virtual Environments: A Primer</a> for detailed instructions on how to do this.</p>
<p>Once you have the virtual environment ready, you can install LlamaIndex from the <a href="/ref/glossary/pypi/" class="ref-link">Python Package Index (PyPI)</a>:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Shell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(.venv)</span> <span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>llama-index
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>This command downloads the framework from PyPI and installs it in your current Python environment. In practice, <a href="https://pypi.org/project/llama-index/"><code>llama-index</code></a> is a <a href="https://developers.llamaindex.ai/python/framework/getting_started/installation/#quickstart-installation-from-pip">core starter bundle</a> of packages containing the following:</p>
<ul>
<li><code>llama-index-core</code></li>
<li><code>llama-index-llms-openai</code></li>
<li><code>llama-index-embeddings-openai</code></li>
<li><code>llama-index-readers-file</code></li>
</ul>
<p>As you can see, OpenAI is the default LLM provider for LlamaIndex. In this tutorial, you’ll rely on this default setting, so after installation, you must set up an environment variable called <code>OPENAI_API_KEY</code> that points to a valid OpenAI <a href="https://platform.openai.com/api-keys">API key</a>:</p>
<ul class="nav nav-tabs justify-content-end js-platform-widget-tabs" role="tablist">
<li class="nav-item mb-0 js-platform-widget-tab-windows" role="presentation">
<a class="nav-link link-unstyled text-body active small" id="windows-tab-1" data-toggle="tab" href="#windows-1" role="tab" aria-controls="windows-1" aria-selected="true"><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#brands--windows"></use></svg></span>Windows</a>
</li>
<li class="nav-item mb-0 js-platform-widget-tab-linuxmacos" role="presentation">
<a class="nav-link link-unstyled text-body small" id="macos-tab-1" data-toggle="tab" href="#linux-macos-1" role="tab" aria-controls="linux-macos-1" aria-selected="false"><span class="icon baseline text-muted" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#v4--linux"></use></svg></span><span class="icon baseline text-muted mr-1" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#v4--apple"></use></svg></span>Linux + macOS</a>
</li>
</ul>
<div class="tab-content mt-2 mb-0 js-platform-widget-content">
<div aria-labelledby="windows-tab-1" class="tab-pane fade show active" id="windows-1" role="tabpanel">
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pscon" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Windows PowerShell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(.venv)</span> <span class="gp">PS> </span><span class="nv">$ENV:OPENAI_API_KEY</span> <span class="p">=</span> <span class="s2">"<your-api-key-here>"</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
</div>
<div aria-labelledby="linux-macos-tab-1" class="tab-pane fade " id="linux-macos-1" role="tabpanel">
<code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Shell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp gp-VirtualEnv">(.venv)</span> <span class="gp">$ </span><span class="nb">export</span><span class="w"> </span><span class="nv">OPENAI_API_KEY</span><span class="o">=</span><span class="s2">"<your-api-key-here>"</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
</div>
</div>
<p>With this command, you make the API key accessible under the environment variable <code>OPENAI_API_KEY</code> in your current <a href="https://realpython.com/terminal-commands/">terminal</a> session. Note that you’ll lose it when you close your terminal. To persist this variable, add the <code>export</code> command to your shell’s configuration file—typically <code>~/.bashrc</code> or <code>~/.zshrc</code> on Linux and macOS—or use the <em>System Properties</em> dialog on Windows.</p>
<p>LlamaIndex also supports many other LLMs. For a complete list of models, visit the <a href="https://developers.llamaindex.ai/python/framework/module_guides/models/llms/modules">Available LLM integrations</a> section in the official <a href="https://developers.llamaindex.ai/python/framework/">documentation</a>.</p>
<h3 id="run-a-quick-llamaindex-rag-example">Run a Quick LlamaIndex RAG Example<a class="headerlink" href="#run-a-quick-llamaindex-rag-example" title="Permanent link"></a></h3>
</div><h2><a href="https://realpython.com/llamaindex-examples/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/llamaindex-examples/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: LlamaIndex in Python: A RAG Guide With Exampleshttps://realpython.com/quizzes/llamaindex-examples/2025-12-24T12:00:00+00:00Take this Python LlamaIndex quiz to test your understanding of index persistence, reloading, and performance gains in RAG applications.
<p>In this quiz, you’ll test your understanding of the <a href="https://realpython.com/llamaindex-examples/">LlamaIndex in Python: A RAG Guide With Examples</a> tutorial.</p>
<p>By working through this quiz, you’ll revisit how to create and persist an index to disk, review how to reload it, and see why persistence improves performance, lowers costs, saves time, and keeps results consistent.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Reading User Input From the Keyboard With Pythonhttps://realpython.com/courses/reading-user-input-from-keyboard/2025-12-23T14:00:00+00:00Master taking user input in Python to build interactive terminal apps with clear prompts, solid error handling, and smooth multi-step flows.
<p>You may often want to make your Python programs more interactive by responding dynamically to input from the user. Learning how to read user input from the keyboard unlocks exciting possibilities and can make your code far more useful.</p>
<p>The ability to gather input from the keyboard with Python allows you to build programs that can respond uniquely based on the preferences, decisions, or data provided by different users. By fetching input and assigning it to variables, your code can react to adjustable conditions rather than just executing static logic flows. This personalizes programs to individual users.</p>
<p>The <code>input()</code> function is the simplest way to get keyboard data from the user in Python. When called, it asks the user for input with a prompt that you specify, and it waits for the user to type a response and press the <span class="keys"><kbd class="key-enter">Enter</kbd></span> key before continuing. This response string is returned by <code>input()</code> so you can save it to a variable or use it directly.</p>
<p>Using only Python, you can start building interactive programs that accept customizable data from the user right within the terminal. Taking user input is an essential skill that unlocks more dynamic Python coding and allows you to elevate simple scripts into personalized applications.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: Recursion in Python: An Introductionhttps://realpython.com/quizzes/python-recursion/2025-12-23T12:00:00+00:00Test your understanding of recursion in Python, including base cases, recursive structure, performance considerations, and common use cases.
<p>In this quiz, you’ll test your understanding of
<a href="https://realpython.com/python-recursion/">Recursion in Python</a>.</p>
<p>By working through this quiz, you’ll revisit what recursion is, how base and recursive cases work, when recursion is a good fit for a problem, and when an iterative approach fits.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
SOLID Design Principles: Improve Object-Oriented Code in Pythonhttps://realpython.com/solid-principles-python/2025-12-22T14:00:00+00:00Learn how to apply SOLID design principles in Python and build maintainable, reusable, and testable object-oriented code.
<div><p>A great approach to writing high-quality object-oriented Python code is to consistently apply the SOLID design principles. SOLID is a set of five object-oriented design principles that can help you write maintainable, flexible, and scalable code based on well-designed, cleanly structured classes. These principles are foundational best practices in object-oriented design.</p>
<p>In this tutorial, you’ll explore each of these principles with concrete examples and refactor your code so that it adheres to the principle at hand.</p>
<p><strong>By the end of this tutorial, you’ll understand that:</strong></p>
<ul>
<li>You apply the <strong>SOLID</strong> design principles to write classes that you can confidently maintain, extend, test, and reason about.</li>
<li>You can apply SOLID principles to split <strong>responsibilities</strong>, extend via <strong>abstractions</strong>, honor <strong>subtype contracts</strong>, keep <strong>interfaces</strong> small, and <strong>invert dependencies</strong>.</li>
<li>You enforce the <strong>Single-Responsibility Principle</strong> by separating tasks into specialized classes, giving each class only <strong>one reason to change</strong>.</li>
<li>You satisfy the <strong>Open-Closed Principle</strong> by defining an abstract class with the required interface and adding new <strong>subclasses</strong> without modifying existing code.</li>
<li>You honor the <strong>Liskov Substitution Principle</strong> by making the subtypes preserve their <strong>expected behaviors</strong>.</li>
<li>You implement <strong>Dependency Inversion</strong> by making your classes depend on <strong>abstractions</strong> rather than on details.</li>
</ul>
<p>Follow the examples to refactor each design, verify behaviors, and internalize how each SOLID design principle can improve your code.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Free Bonus:</strong> <a href="https://realpython.com/bonus/solid-principles-python-code/" class="alert-link" data-toggle="modal" data-target="#modal-solid-principles-python-code" markdown>Click here to download sample code</a> so you can build clean, maintainable classes with the SOLID Principles in Python.</p>
</div>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “SOLID Design Principles: Improve Object-Oriented Code in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/solid-principles-python/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #ffc873;" alt="SOLID Principles: Improve Object-Oriented Design in Python" src="https://files.realpython.com/media/The-SOLID-Principles-in-Python-Improve-Your-OOP-Design_Watermarked.a70bbae152e8.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/The-SOLID-Principles-in-Python-Improve-Your-OOP-Design_Watermarked.a70bbae152e8.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/The-SOLID-Principles-in-Python-Improve-Your-OOP-Design_Watermarked.a70bbae152e8.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/The-SOLID-Principles-in-Python-Improve-Your-OOP-Design_Watermarked.a70bbae152e8.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/The-SOLID-Principles-in-Python-Improve-Your-OOP-Design_Watermarked.a70bbae152e8.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/solid-principles-python/" class="stretched-link"><span class="my-0 h4">SOLID Design Principles: Improve Object-Oriented Code in Python</span></a>
<p class="text-muted mb-0 small">Test your Python understanding of Liskov substitution, Square–Rectangle pitfalls, and safer API design with polymorphism.</p>
</div>
</div>
</div>
<h2 id="the-solid-design-principles-in-python">The SOLID Design Principles in Python<a class="headerlink" href="#the-solid-design-principles-in-python" title="Permanent link"></a></h2>
<p>When it comes to writing <a href="https://realpython.com/python-classes/">classes</a> and designing their interactions in Python, you can follow a series of principles that will help you build better object-oriented code. One of the most popular and widely accepted sets of standards for <a href="https://en.wikipedia.org/wiki/Object-oriented_design">object-oriented design (OOD)</a> is known as the <a href="https://en.wikipedia.org/wiki/SOLID">SOLID</a> design principles.</p>
<p>If you’re coming from <a href="https://realpython.com/python-vs-cpp/">C++</a> or <a href="https://realpython.com/oop-in-python-vs-java/">Java</a>, you may already be familiar with these principles. Maybe you’re wondering if the SOLID principles also apply to Python code. The answer to that question is a resounding <em>yes</em>. If you’re writing object-oriented code, then you should consider applying these principles to your OOD.</p>
<p>But what are these SOLID design principles? SOLID is an acronym that encompasses five core principles applicable to object-oriented design. These principles are the following:</p>
<ol>
<li><a href="https://en.wikipedia.org/wiki/Single-responsibility_principle"><strong>S</strong>ingle-responsibility principle (SRP)</a></li>
<li><a href="https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle"><strong>O</strong>pen–closed principle (OCP)</a></li>
<li><a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle"><strong>L</strong>iskov substitution principle (LSP)</a></li>
<li><a href="https://en.wikipedia.org/wiki/Interface_segregation_principle"><strong>I</strong>nterface segregation principle (ISP)</a></li>
<li><a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle"><strong>D</strong>ependency inversion principle (DIP)</a></li>
</ol>
<p>You’ll explore each of these principles in detail and code real-world examples of how to apply them in Python. In the process, you’ll gain a strong understanding of how to write more straightforward, organized, scalable, and reusable object-oriented code by applying the SOLID design principles. To kick things off, you’ll start with the first principle on the list.</p>
<h2 id="single-responsibility-principle-srp">Single-Responsibility Principle (SRP)<a class="headerlink" href="#single-responsibility-principle-srp" title="Permanent link"></a></h2>
<p>The <strong>single-responsibility principle (SRP)</strong> comes from <a href="https://en.wikipedia.org/wiki/Robert_C._Martin">Robert C. Martin</a>, more commonly known by his nickname Uncle Bob. Martin is a well-respected figure in software engineering and one of the original signatories of the <a href="https://en.wikipedia.org/wiki/Agile_software_development#The_Agile_Manifesto">Agile Manifesto</a>. He coined the term <strong>SOLID</strong>.</p>
<p>The single-responsibility principle states that:</p>
<blockquote>
<p>A class should have only one reason to change.</p>
</blockquote>
<p>This means that a class should have only one <strong>responsibility</strong>, as expressed through its <a href="/ref/glossary/method/" class="ref-link">methods</a>. If a class takes care of more than one task, then you should separate those tasks into dedicated classes with descriptive names. Note that SRP isn’t only about <em>responsibility</em> but also about the <em>reasons for changing</em> the class implementation.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> You’ll find the SOLID design principles worded in various ways out there. In this tutorial, you’ll refer to them following the wording that Uncle Bob uses in his book <a href="https://realpython.com/asins/0131857258/">Agile Software Development: Principles, Patterns, and Practices</a>. So, all the direct quotes come from this book.</p>
<p>If you want to read alternate wordings in a quick roundup of these and related principles, then check out Uncle Bob’s <a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">The Principles of OOD</a>.</p>
</div>
<p>This principle is closely related to the concept of <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a>, which suggests that you should divide your programs into components, each addressing a separate concern.</p>
<p>To illustrate the single-responsibility principle and how it can help you improve your object-oriented design, say that you have the following <code>FileManager</code> class:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="python">
<div class="codeblock__header codeblock--blue">
<span class="mr-2 noselect" aria-label="Language">Python</span>
<span class="mr-2" aria-label="Filename"><code style="color: inherit; background: inherit;">file_manager_srp.py</code></span>
<div class="noselect">
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="kn">from</span><span class="w"> </span><span class="nn">pathlib</span><span class="w"> </span><span class="kn">import</span> <span class="n">Path</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">zipfile</span><span class="w"> </span><span class="kn">import</span> <span class="n">ZipFile</span>
<span class="k">class</span><span class="w"> </span><span class="nc">FileManager</span><span class="p">:</span>
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">"utf-8"</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">read_text</span><span class="p">(</span><span class="n">encoding</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">"utf-8"</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">write_text</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">encoding</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">compress</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">with</span> <span class="n">ZipFile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s2">".zip"</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s2">"w"</span><span class="p">)</span> <span class="k">as</span> <span class="n">archive</span><span class="p">:</span>
<span class="n">archive</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">)</span>
<span class="k">def</span><span class="w"> </span><span class="nf">decompress</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">with</span> <span class="n">ZipFile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">with_suffix</span><span class="p">(</span><span class="s2">".zip"</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s2">"r"</span><span class="p">)</span> <span class="k">as</span> <span class="n">archive</span><span class="p">:</span>
<span class="n">archive</span><span class="o">.</span><span class="n">extractall</span><span class="p">()</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>In this example, your <code>FileManager</code> class has two different responsibilities. It manages files using the <code>.read()</code> and <code>.write()</code> methods. It also deals with <a href="https://realpython.com/python-zipfile/">ZIP archives</a> by providing the <code>.compress()</code> and <code>.decompress()</code> methods.</p>
<p>This class violates the single-responsibility principle because there is more than one reason for changing its implementation (file <a href="/ref/glossary/input-output/" class="ref-link">I/O</a> and ZIP handling). This implementation also makes code testing and code reuse harder.</p>
<p>To fix this issue and make your design more robust, you can split the class into two smaller, more focused classes, each with its own specific concern:</p>
</div><h2><a href="https://realpython.com/solid-principles-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/solid-principles-python/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: SOLID Design Principles: Improve Object-Oriented Code in Pythonhttps://realpython.com/quizzes/solid-principles-python/2025-12-22T12:00:00+00:00Test your Python understanding of Liskov substitution, Square–Rectangle pitfalls, and safer API design with polymorphism.
<p>In this quiz, you’ll test your understanding of the <a href="https://realpython.com/solid-principles-python/">SOLID Design Principles: Improve Object-Oriented Code in Python</a> tutorial.</p>
<p>You will reason about behavior contracts, attribute invariants, and choosing composition or separate types over inheritance. For a refresher, you can watch the <a href="https://realpython.com/courses/solid-principles-python/">Design and Guidance: Object-Oriented Programming in Python</a> course.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #277: Moving Towards Spec-Driven Developmenthttps://realpython.com/podcasts/rpp/277/2025-12-19T12:00:00+00:00What are the advantages of spec-driven development compared to vibe coding with an LLM? Are these recent trends a move toward declarative programming? This week on the show, Marc Brooker, VP and Distinguished Engineer at AWS, joins us to discuss specification-driven development and Kiro.
<p>What are the advantages of spec-driven development compared to vibe coding with an LLM? Are these recent trends a move toward declarative programming? This week on the show, Marc Brooker, VP and Distinguished Engineer at AWS, joins us to discuss specification-driven development and Kiro.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
How to Build the Python Skills That Get You Hiredhttps://realpython.com/python-skills/2025-12-17T14:00:00+00:00Build a focused learning plan that helps you identify essential Python skills, assess your strengths, and practice effectively to progress.
<div><p>When you’re learning Python, the sheer volume of topics to explore can feel overwhelming because there’s <em>so much</em> you could focus on. Should you dive into web frameworks before exploring data science? Is test-driven development something you need right away? And which skills actually matter to employers in the age of AI-assisted software development?</p>
<p><strong>By the end of this tutorial, you’ll have:</strong></p>
<ul>
<li>A clear understanding of which <strong>Python skills</strong> employers consistently look for</li>
<li>A personalized <strong>Python developer roadmap</strong> showing where you are and where you need to go</li>
<li>A <strong>weekly practice plan</strong> that makes consistent progress feel achievable</li>
</ul>
<p>Python itself is relatively beginner-friendly, but its versatility makes it easy to wander without direction. Without a clear plan, you can spend months studying topics that won’t help you land your first developer job.</p>
<p>This guide will show you how to build a focused learning strategy that aligns with real job market demands. You’ll learn how to research what employers value, assess your current strengths and gaps, and structure a practice routine that turns scattered study sessions into steady progress.</p>
<p>Instead of guessing what to learn next, you’ll have a concrete document that shows you exactly where to focus:</p>
<figure class="js-lightbox"><a href="https://files.realpython.com/media/python-skills-worksheet-link.4e0ad67920ee.png" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block border " src="https://files.realpython.com/media/python-skills-worksheet-link.4e0ad67920ee.png" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/python-skills-worksheet-link.4e0ad67920ee.png 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/python-skills-worksheet-link.4e0ad67920ee.png 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/python-skills-worksheet-link.4e0ad67920ee.png 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/python-skills-worksheet-link.4e0ad67920ee.png 1920w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="The Python skills worksheet as a table with one row filled out and a link showing on hover" data-asset="6692"></a></figure>
<p>Work through this tutorial to identify the skills you need and set yourself up for success.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Downloads:</strong> <a href="https://realpython.com/bonus/python-skills-materials/" class="alert-link" data-toggle="modal" data-target="#modal-python-skills-materials" markdown>Click here to download the free materials</a> that will help you build the Python skills that get you hired.</p>
</div>
<h2 id="step-1-identify-the-python-skills-employers-value-most">Step 1: Identify the Python Skills Employers Value Most<a class="headerlink" href="#step-1-identify-the-python-skills-employers-value-most" title="Permanent link"></a></h2>
<p>Before you dive into another tutorial or framework, you need to understand what the job market actually rewards. Most Python learners make the mistake of studying everything that sounds interesting. You’ll make faster progress by focusing on the skills that appear in job posting after job posting.</p>
<h3 id="research-real-job-requirements">Research Real Job Requirements<a class="headerlink" href="#research-real-job-requirements" title="Permanent link"></a></h3>
<p>Start by opening five to ten current job listings for Python-related positions. Look for titles like <em>Python Developer</em>, <em>Backend Engineer</em>, <em>Data Analyst</em>, or <em>Machine Learning Engineer</em> on sites like <a href="https://www.indeed.com/">Indeed</a>, <a href="https://stackoverflowjobs.com/">Stack Overflow Jobs</a>, and <a href="https://www.linkedin.com/jobs/">LinkedIn</a>. As you read through these postings, highlight the <strong>technical requirements</strong> that appear repeatedly. You’ll quickly start to notice patterns.</p>
<p>To illustrate, consider a few examples of different roles involving Python:</p>
<ul>
<li><a href="https://realpython.com/learning-paths/become-python-web-developer/">Web development</a> roles often emphasize frameworks like <a href="https://realpython.com/learning-paths/flask-by-example/">Flask</a>, <a href="https://realpython.com/learning-paths/django-web-development/">Django</a>, and, more recently, <a href="https://realpython.com/get-started-with-fastapi/">FastAPI</a>, along with <a href="https://realpython.com/learning-paths/database-access-in-python/">database</a> knowledge and <a href="https://realpython.com/api-integration-in-python/">REST API</a> design. Employers often seek full-stack engineers who feel comfortable working on the backend as well as <a href="https://realpython.com/tutorials/front-end/">frontend</a>, including <a href="https://realpython.com/python-vs-javascript/">JavaScript</a>, <a href="https://realpython.com/html-css-python/">HTML, and CSS</a>.</li>
<li><a href="https://realpython.com/learning-paths/data-science-python-core-skills/">Data science</a> positions highlight libraries like <a href="https://realpython.com/numpy-tutorial/">NumPy</a>, <a href="https://realpython.com/learning-paths/pandas-data-science/">pandas</a>, <a href="https://realpython.com/polars-python/">Polars</a>, and <a href="https://realpython.com/python-matplotlib-guide/">Matplotlib</a>, plus an understanding of <a href="https://realpython.com/python-statistics/">statistical concepts</a>.</li>
<li><a href="https://realpython.com/learning-paths/machine-learning-python/">Machine learning</a> jobs typically add <a href="https://realpython.com/pytorch-vs-tensorflow/">PyTorch or TensorFlow</a> to the mix.</li>
<li><a href="https://en.wikipedia.org/wiki/Test_automation">Test automation</a> roles likely require familiarity with frameworks such as <a href="https://realpython.com/modern-web-automation-with-python-and-selenium/">Selenium</a>, Playwright, or <a href="https://realpython.com/web-scraping-with-scrapy-and-mongodb/">Scrapy</a>.</li>
</ul>
<p>Despite these differences, nearly every job posting shares a <strong>common core</strong>. Employers want developers who understand <a href="https://realpython.com/learning-paths/python3-introduction/">Python fundamentals</a> deeply. They should also be able to use version control with <a href="https://realpython.com/python-git-github-intro/">Git</a>, write <a href="https://realpython.com/learning-paths/test-your-python-apps/">unit tests</a> for their code, and <a href="https://realpython.com/learning-paths/exception-handling-logging-debugging/">debug</a> problems systematically. Familiarity with <a href="https://realpython.com/learning-paths/python-devops/">DevOps</a> practices and <a href="https://realpython.com/django-hosting-on-heroku/">cloud platforms</a> is often a plus. These professional practices matter as much as knowing any specific framework.</p>
<p>Increasingly, job postings also expect familiarity with <a href="/ref/ai-coding-tools/" class="ref-link">AI coding tools</a> like <a href="/ref/ai-coding-tools/github-copilot-chat/" class="ref-link">GitHub Copilot</a>, <a href="/ref/ai-coding-tools/gemini-cli/" class="ref-link">Gemini CLI</a>, <a href="/ref/ai-coding-tools/cursor/" class="ref-link">Cursor</a>, or <a href="/ref/ai-coding-tools/claude-code/" class="ref-link">Claude Code</a>. Employers want developers who can use these tools productively while maintaining the judgment to review and validate AI-generated code.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> With AI tools handling more routine coding tasks, employers increasingly value developers who can <em>think at the system level</em>. </p>
<p>Understanding how components fit together, how to design scalable architectures, and how to make sound trade-offs between approaches matters more than ever. These system design skills are harder to outsource to AI because they require judgment about business requirements, user needs, and long-term maintainability.</p>
</div>
<p>Your informal survey will reflect what large-scale research confirms. The <a href="https://survey.stackoverflow.co/2025/technology#most-popular-technologies">Stack Overflow Developer Survey</a> ranks Python as one of the most widely used programming languages across all professional roles. The survey also reveals that Python appears in diverse fields, including finance, healthcare, education, and scientific research.</p>
<p>This trend is echoed by the <a href="https://www.tiobe.com/tiobe-index/">TIOBE Index</a>, a monthly ranking of programming language popularity, where Python consistently appears at or near the top:</p>
<figure class="js-lightbox"><a href="https://files.realpython.com/media/Screenshot_From_2025-11-13_19-05-15.a6ccfe59dec8.png" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block border " src="https://files.realpython.com/media/Screenshot_From_2025-11-13_19-05-15.a6ccfe59dec8.png" width="1378" height="465" srcset="/cdn-cgi/image/width=344,format=auto/https://files.realpython.com/media/Screenshot_From_2025-11-13_19-05-15.a6ccfe59dec8.png 344w, /cdn-cgi/image/width=459,format=auto/https://files.realpython.com/media/Screenshot_From_2025-11-13_19-05-15.a6ccfe59dec8.png 459w, /cdn-cgi/image/width=689,format=auto/https://files.realpython.com/media/Screenshot_From_2025-11-13_19-05-15.a6ccfe59dec8.png 689w, /cdn-cgi/image/width=1378,format=auto/https://files.realpython.com/media/Screenshot_From_2025-11-13_19-05-15.a6ccfe59dec8.png 1378w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="TIOBE Index" data-asset="6643"></a><figcaption class="figure-caption text-center">TIOBE Index</figcaption></figure>
<p>Similarly, LinkedIn’s <a href="https://learning.linkedin.com/resources/workplace-learning-report-2023">Workplace Learning Report 2023</a> named Python as one of the most in-demand technical skills globally. Python’s versatility means that mastering its fundamentals opens doors across multiple career paths.</p>
<h3 id="understand-different-developer-paths">Understand Different Developer Paths<a class="headerlink" href="#understand-different-developer-paths" title="Permanent link"></a></h3>
<p>Python is a phenomenally versatile language. On the one hand, school teachers choose it to help their pupils learn how to program, often starting with fun, visual tools like the built-in <a href="https://realpython.com/beginners-guide-python-turtle/"><code>turtle</code> graphics</a> module. At the same time, Python runs major platforms like Instagram, plays a role in powering large services such as YouTube, and supports the development of generative AI models. It even once helped <a href="https://realpython.com/python-news-march-2021/#python-lands-on-mars">control the helicopter</a> flying on Mars!</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> Check out <a href="https://realpython.com/what-can-i-do-with-python/">What Can I Do With Python?</a> to discover how Python helps build software, power AI, automate tasks, drive robotics, and more.</p>
</div>
</div><h2><a href="https://realpython.com/python-skills/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-skills/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Exploring Asynchronous Iterators and Iterableshttps://realpython.com/courses/asynchronous-iterators-iterables/2025-12-16T14:00:00+00:00Learn to build async iterators and iterables in Python to handle async operations efficiently and write cleaner, faster code.
<p>When you write asynchronous code in Python, you’ll likely need to create asynchronous iterators and iterables at some point. Asynchronous iterators are what Python uses to control <code>async for</code> loops, while asynchronous iterables are objects that you can iterate over using <code>async for</code> loops.</p>
<p>Both tools allow you to iterate over awaitable objects without blocking your code. This way, you can perform different tasks asynchronously.</p>
<p><strong>In this video course, you’ll:</strong></p>
<ul>
<li>Learn what <strong>async iterators</strong> and <strong>iterables</strong> are in Python</li>
<li>Create async <strong>generator expressions</strong> and <strong>generator iterators</strong></li>
<li>Code async iterators and iterables with the <strong><code>.__aiter__()</code></strong> and <strong><code>.__anext__()</code></strong> methods</li>
<li>Use async iterators in <strong>async loops</strong> and <strong>comprehensions</strong></li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Writing DataFrame-Agnostic Python Code With Narwhalshttps://realpython.com/narwhals-python/2025-12-15T14:00:00+00:00If you're a Python library developer looking to write DataFrame-agnostic code, this tutorial will show how the Narwhals library could give you a solution.
<div><p>Narwhals is intended for Python library developers who need to analyze DataFrames in a range of standard formats, including Polars, pandas, DuckDB, and others. It does this by providing a compatibility layer of code that handles any differences between the various formats.</p>
<p>In this tutorial, you’ll learn how to use the same Narwhals code to analyze data produced by the latest versions of two very common data libraries. You’ll also discover how Narwhals utilizes the efficiencies of your source data’s underlying library when analyzing your data. Furthermore, because Narwhals uses syntax that is a subset of Polars, you can reuse your existing Polars knowledge to quickly gain proficiency with Narwhals.</p>
<p>The table below will allow you to quickly decide whether or not Narwhals is for you:</p>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Use Case</th>
<th class="text-center">Use Narwhals</th>
<th class="text-center">Use Another Tool</th>
</tr>
</thead>
<tbody>
<tr>
<td>You need to produce DataFrame-agnostic code.</td>
<td class="text-center">✅</td>
<td class="text-center">❌</td>
</tr>
<tr>
<td>You want to learn a new DataFrame library.</td>
<td class="text-center">❌</td>
<td class="text-center">✅</td>
</tr>
</tbody>
</table>
</div>
<p>Whether you’re wondering how to develop a Python library to cope with DataFrames from a range of common formats, or just curious to find out if this is even possible, this tutorial is for you. The Narwhals library could provide exactly what you’re looking for.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/narwhals-python-code/" class="alert-link" data-toggle="modal" data-target="#modal-narwhals-python-code" markdown>Click here to download the free sample code and data files</a> that you’ll use to work with Narwhals in Python.</p>
</div>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Writing DataFrame-Agnostic Python Code With Narwhals” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/narwhals-python/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #abe5b2;" alt="Writing DataFrame-Agnostic Python Code With Narwhals" src="https://files.realpython.com/media/Narwhals-Python-DataFrameInteroperability-for-Pandas-Polars--More_Watermarked.ff492f3b2207.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Narwhals-Python-DataFrameInteroperability-for-Pandas-Polars--More_Watermarked.ff492f3b2207.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Narwhals-Python-DataFrameInteroperability-for-Pandas-Polars--More_Watermarked.ff492f3b2207.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Narwhals-Python-DataFrameInteroperability-for-Pandas-Polars--More_Watermarked.ff492f3b2207.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Narwhals-Python-DataFrameInteroperability-for-Pandas-Polars--More_Watermarked.ff492f3b2207.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/narwhals-python/" class="stretched-link"><span class="my-0 h4">Writing DataFrame-Agnostic Python Code With Narwhals</span></a>
<p class="text-muted mb-0 small">If you're a Python library developer wondering how to write DataFrame-agnostic code, the Narwhals library is the solution you're looking for.</p>
</div>
</div>
</div>
<h2 id="get-ready-to-explore-narwhals">Get Ready to Explore Narwhals<a class="headerlink" href="#get-ready-to-explore-narwhals" title="Permanent link"></a></h2>
<p>Before you start, you’ll need to install Narwhals and have some data to play around with. You should also be familiar with the idea of a DataFrame. Although having an understanding of several DataFrame libraries isn’t mandatory, you’ll find a familiarity with <a href="https://realpython.com/polars-python/#dataframes-expressions-and-contexts">Polars’ expressions and contexts syntax</a> extremely useful. This is because Narwhals’ syntax is based on a subset of Polars’ syntax. However, Narwhals doesn’t replace Polars.</p>
<p>In this example, you’ll use data stored in the <code>presidents</code> <a href="https://en.wikipedia.org/wiki/Apache_Parquet">Parquet</a> file included in your downloadable materials.</p>
<p>This file contains the following six fields to describe <a href="https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States">United States presidents</a>:</p>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Heading</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>last_name</code></td>
<td>The president’s last name</td>
</tr>
<tr>
<td><code>first_name</code></td>
<td>The president’s first name</td>
</tr>
<tr>
<td><code>term_start</code></td>
<td>Start of the presidential term</td>
</tr>
<tr>
<td><code>term_end</code></td>
<td>End of the presidential term</td>
</tr>
<tr>
<td><code>party_name</code></td>
<td>The president’s political party</td>
</tr>
<tr>
<td><code>century</code></td>
<td>Century the president’s term started</td>
</tr>
</tbody>
</table>
</div>
<p>To work through this tutorial, you’ll need to install the <a href="https://pandas.pydata.org/docs/">pandas</a>, <a href="https://pola.rs/">Polars</a>, <a href="https://pyarrow.readthedocs.io/en/latest/">PyArrow</a>, and <a href="https://narwhals-dev.github.io/narwhals/">Narwhals</a> libraries:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Shell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>pandas<span class="w"> </span>polars<span class="w"> </span>pyarrow<span class="w"> </span>narwhals
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>A key feature of Narwhals is that it’s DataFrame-agnostic, meaning your code can work with several formats. But you still need both Polars and pandas because Narwhals will use them to process the data you pass to it. You’ll also need them to create your DataFrames to pass to Narwhals to begin with.</p>
<p>You installed the PyArrow library to correctly read the Parquet files. Finally, you installed Narwhals itself.</p>
<p>With everything installed, make sure you create the project’s folder and place your downloaded <code>presidents.parquet</code> file inside it. You might also like to add both the <code>books.parquet</code> and <code>authors.parquet</code> files as well. You’ll need them later. </p>
<p>With that lot done, you’re good to go!</p>
<h2 id="understand-how-narwhals-works">Understand How Narwhals Works<a class="headerlink" href="#understand-how-narwhals-works" title="Permanent link"></a></h2>
<p>The documentation describes Narwhals as follows:</p>
<blockquote>
<p>Extremely lightweight and extensible compatibility layer between dataframe libraries! (<a href="https://narwhals-dev.github.io/narwhals/">Source</a>)</p>
</blockquote>
<p>Narwhals is <strong>lightweight</strong> because it wraps the original DataFrame in its own object ecosystem while still using the source DataFrame’s library to process it. Any data passed into it for processing doesn’t need to be duplicated, removing an otherwise resource-intensive and time-consuming operation.</p>
<p>Narwhals is also <strong>extensible</strong>. For example, you can write Narwhals code to work with the full API of the following libraries:</p>
<ul>
<li><a href="https://github.com/rapidsai/cudf">cuDF</a></li>
<li><a href="https://github.com/modin-project/modin">Modin</a></li>
<li><a href="https://pandas.pydata.org/">pandas</a></li>
<li><a href="https://pola.rs/">Polars</a></li>
<li><a href="https://arrow.apache.org/docs/python/">PyArrow</a></li>
</ul>
<p>It also supports the lazy API of the following:</p>
</div><h2><a href="https://realpython.com/narwhals-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/narwhals-python/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: Writing DataFrame-Agnostic Python Code With Narwhalshttps://realpython.com/quizzes/narwhals-python/2025-12-15T12:00:00+00:00If you're a Python library developer wondering how to write DataFrame-agnostic code, the Narwhals library is the solution you're looking for.
<p>In this quiz, you’ll test your understanding of what the Narwhals library offers you.</p>
<p>By working through this quiz, you’ll revisit many of the concepts presented in the <a href="https://realpython.com/narwhals-python/">Writing DataFrame-Agnostic Code With Narwhals </a> tutorial.</p>
<p>Remember, also, the <a href="https://narwhals-dev.github.io/narwhals/">official documentation</a> is a great reference source for the latest Narwhals developments.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Python Inner Functions: What Are They Good For?https://realpython.com/inner-functions-what-are-they-good-for/2025-12-10T14:00:00+00:00Learn how to create inner functions in Python to access nonlocal names, build stateful closures, and create decorators.
<div><p>Python inner functions are those you define inside other functions to access <a href="/ref/keywords/nonlocal/" class="ref-link"><code>nonlocal</code></a> names and bundle logic with its surrounding state. In this tutorial, you’ll learn how to create inner helper functions, build closures that retain state across calls, and implement decorators that modify the behavior or existing callables without changing the original implementation.</p>
<p><strong>By the end of this tutorial, you’ll understand that:</strong></p>
<ul>
<li>Inner functions access <strong>nonlocal names</strong> from the enclosing scope, so you pass data in once and reuse it across calls.</li>
<li>You can replace an <strong>inner helper function</strong> with a <strong>non-public</strong> function to enable code reuse.</li>
<li>You can create a <strong>closure</strong> by returning the inner function without calling it, which preserves the captured environment.</li>
<li>You can <strong>modify the captured state</strong> by declaring nonlocal variables that point to <strong>mutable objects</strong>.</li>
<li>You craft <strong>decorators</strong> with nested functions that wrap a callable and extend its behavior transparently.</li>
</ul>
<p>You will now move through focused examples that feature encapsulated helpers, stateful closures, and decorator patterns, allowing you to apply each technique with confidence in real Python projects.</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/python-inner-functions-code/" class="alert-link" data-toggle="modal" data-target="#modal-python-inner-functions-code" markdown>Click here to download the free sample code</a> to practice inner functions in Python.</p>
</div>
<div class="container border rounded text-wrap-pretty my-3">
<p class="my-3"><mark class="marker-highlight"><strong><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Python Inner Functions: What Are They Good For?” quiz. You’ll receive a score upon completion to help you track your learning progress:</p>
<hr>
<div class="row my-3">
<div class="col-xs-12 col-sm-4 col-md-3 align-self-center">
<a href="/quizzes/inner-functions-what-are-they-good-for/" tabindex="-1">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top m-0 p-0 embed-responsive-item rounded" style="object-fit: contain; background: #ffc873;" alt="Python Inner Functions" src="https://files.realpython.com/media/Inner-Functions-What-Are-They-Good-For_Watermarked.995d44a06cdd.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Inner-Functions-What-Are-They-Good-For_Watermarked.995d44a06cdd.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Inner-Functions-What-Are-They-Good-For_Watermarked.995d44a06cdd.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Inner-Functions-What-Are-They-Good-For_Watermarked.995d44a06cdd.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Inner-Functions-What-Are-They-Good-For_Watermarked.995d44a06cdd.jpg 1920w" sizes="(min-width: 1200px) 142px, (min-width: 1000px) 122px, (min-width: 780px) 112px, (min-width: 580px) 139px, calc(100vw - 62px)">
<div class="card-img-overlay d-flex align-items-center">
<div class="mx-auto">
<span class="text-light" style="opacity: 0.90;"><span class="icon baseline scale2x" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@quiz"></use></svg></span></span>
</div>
</div>
</div>
</a>
</div>
<div class="col">
<div class="mt-3 d-md-none"></div>
<p class="small text-muted mb-0"><strong>Interactive Quiz</strong></p>
<a href="/quizzes/inner-functions-what-are-they-good-for/" class="stretched-link"><span class="my-0 h4">Python Inner Functions: What Are They Good For?</span></a>
<p class="text-muted mb-0 small">Test inner functions, closures, nonlocal, and decorators in Python. Build confidence and learn to keep state across calls. Try the quiz now.</p>
</div>
</div>
</div>
<h2 id="creating-functions-within-functions-in-python">Creating Functions Within Functions in Python<a class="headerlink" href="#creating-functions-within-functions-in-python" title="Permanent link"></a></h2>
<p>A <a href="/ref/glossary/function/" class="ref-link">function</a> defined inside another function is known as an <strong>inner function</strong> or a <strong>nested function</strong>. Yes, in Python, you can define a function within another function. This type of function can access names defined in the <a href="https://realpython.com/python-scope-legb-rule/#the-enclosing-scope">enclosing scope</a>.</p>
<p>Here’s an example of how to create an inner function in Python:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true">
<div class="codeblock__header codeblock--blue">
<span class="mr-2 noselect" aria-label="Language">Python</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">>>> </span><span class="k">def</span><span class="w"> </span><span class="nf">outer_func</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">def</span><span class="w"> </span><span class="nf">inner_func</span><span class="p">():</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Hello, World!"</span><span class="p">)</span>
<span class="gp">... </span> <span class="n">inner_func</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">outer_func</span><span class="p">()</span>
<span class="go">Hello, World!</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>In this example, you define <code>inner_func()</code> inside <code>outer_func()</code> to <a href="https://realpython.com/python-print/">print</a> the <code>Hello, World!</code> message to the screen. To do that, you call <code>inner_func()</code> on the last line of <code>outer_func()</code>. This is the quickest way to write and use an inner function in Python.</p>
<p>Inner functions provide several interesting possibilities beyond what you see in the example above. The core feature of inner functions is their ability to access variables and objects from their enclosing function even after that function has returned. The enclosing function provides a <a href="https://realpython.com/python-namespaces-scope/">namespace</a> that is accessible to the inner function:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true">
<div class="codeblock__header codeblock--blue">
<span class="mr-2 noselect" aria-label="Language">Python</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">>>> </span><span class="k">def</span><span class="w"> </span><span class="nf">outer_func</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">def</span><span class="w"> </span><span class="nf">inner_func</span><span class="p">():</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Hello, </span><span class="si">{</span><span class="n">who</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="gp">... </span> <span class="n">inner_func</span><span class="p">()</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">outer_func</span><span class="p">(</span><span class="s2">"World!"</span><span class="p">)</span>
<span class="go">Hello, World!</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>Note how you can pass a <a href="https://realpython.com/python-strings/">string</a> as an <a href="/ref/glossary/argument/" class="ref-link">argument</a> to <code>outer_func()</code>, and <code>inner_func()</code> can access that argument through the name <code>who</code>. This name is defined in the <a href="https://realpython.com/python-scope-legb-rule/#the-local-scope">local scope</a> of <code>outer_func()</code>. The names defined in the local scope of an outer function are <strong>nonlocal names</strong> from the inner function’s point of view.</p>
<p>Here’s an example of a more realistic inner function:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="pycon" data-is-repl="true">
<div class="codeblock__header codeblock--blue">
<span class="mr-2 noselect" aria-label="Language">Python</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">>>> </span><span class="k">def</span><span class="w"> </span><span class="nf">factorial</span><span class="p">(</span><span class="n">number</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">number</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">"number must be an integer"</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">if</span> <span class="n">number</span> <span class="o"><</span> <span class="mi">0</span><span class="p">:</span>
<span class="gp">... </span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"number must be zero or positive"</span><span class="p">)</span>
<span class="gp">...</span>
<span class="hll"><span class="gp">... </span> <span class="k">def</span><span class="w"> </span><span class="nf">inner_factorial</span><span class="p">(</span><span class="n">number</span><span class="p">):</span>
</span><span class="gp">... </span> <span class="k">if</span> <span class="n">number</span> <span class="o"><=</span> <span class="mi">1</span><span class="p">:</span>
<span class="gp">... </span> <span class="k">return</span> <span class="mi">1</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">number</span> <span class="o">*</span> <span class="n">inner_factorial</span><span class="p">(</span><span class="n">number</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">inner_factorial</span><span class="p">(</span><span class="n">number</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">factorial</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="go">24</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>In <code>factorial()</code>, you first validate the input data to ensure that the user provides an integer that is equal to or greater than zero. Then, you define a <a href="/ref/glossary/recursion/" class="ref-link">recursive</a> inner function called <code>inner_factorial()</code>. This function performs the factorial calculation and <a href="https://realpython.com/python-return-statement/">returns</a> the result. The final step is to call <code>inner_factorial()</code>.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> For a more detailed discussion on recursion and recursive functions, check out <a href="https://realpython.com/python-thinking-recursively/">Thinking Recursively in Python</a> and <a href="https://realpython.com/python-recursion/">Recursion in Python: An Introduction</a>.</p>
</div>
<p>An advantage of using the pattern in the example above is that you perform all the argument validation in the outer function, so you can skip error checking in the inner function and focus on the computation at hand.</p>
<h2 id="using-inner-functions-in-python">Using Inner Functions in Python<a class="headerlink" href="#using-inner-functions-in-python" title="Permanent link"></a></h2>
<p>The use cases of Python inner functions are varied. You can use them to provide <a href="https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)">encapsulation</a>, hiding your functions from external access. You can also write quick helper inner functions. Finally, you can use inner functions to create <a href="https://realpython.com/python-closure/">closures</a> and <a href="https://realpython.com/primer-on-python-decorators/">decorators</a>.</p>
<p>In this section, you’ll learn about the former two use cases of inner functions, and in later sections, you’ll learn how to create <a href="#retaining-state-in-a-closure">closures</a> and <a href="#building-decorators-with-nested-functions-in-python">decorators</a>.</p>
<h3 id="providing-encapsulation">Providing Encapsulation<a class="headerlink" href="#providing-encapsulation" title="Permanent link"></a></h3>
<p>A common use case of inner functions arises when you need to protect or hide a given function from everything happening outside of it, so that the function is completely hidden from the global <a href="https://realpython.com/python-scope-legb-rule/">scope</a>. This type of behavior is known as <a href="/ref/glossary/encapsulation/" class="ref-link"><strong>encapsulation</strong></a>.</p>
<p>Here’s an example that showcases the concept:</p>
</div><h2><a href="https://realpython.com/inner-functions-what-are-they-good-for/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/inner-functions-what-are-they-good-for/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: Python Inner Functions: What Are They Good For?https://realpython.com/quizzes/inner-functions-what-are-they-good-for/2025-12-10T12:00:00+00:00Test inner functions, closures, nonlocal, and decorators in Python. Build confidence and learn to keep state across calls. Try the quiz now.
<p>In this quiz, you’ll test your understanding of the <a href="https://realpython.com/inner-functions-what-are-they-good-for/">Python Inner Functions: What Are They Good For?</a> tutorial.</p>
<p>By working through this quiz, you’ll revisit how inner functions work with enclosing scopes, when to use <code>nonlocal</code> to update captured state, how closures retain data across calls, and how decorators wrap a callable to extend behavior.</p>
<p>You’ll apply these ideas to organize helpers, reuse state, and write clear, maintainable functions in real projects.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Using Functional Programming in Pythonhttps://realpython.com/courses/using-functional-programming/2025-12-09T14:00:00+00:00Boost your Python skills with a quick dive into functional programming: what it is, how Python supports it, and why it matters.
<p><strong>Functional programming</strong> is a programming paradigm in which the primary method of computation is the evaluation of functions. But how does Python support functional programming?</p>
<p><strong>In this video course, you’ll learn:</strong></p>
<ul>
<li>What the <strong>functional programming</strong> paradigm entails</li>
<li>What it means to say that <strong>functions</strong> are <strong>first-class citizens</strong> in Python</li>
<li>How to define <strong>anonymous functions</strong> with the <strong><code>lambda</code></strong> keyword</li>
<li>How to implement functional code using <strong><code>map()</code></strong>, <strong><code>filter()</code></strong>, and <strong><code>reduce()</code></strong></li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Lazy Imports Land in Python and Other Python News for December 2025https://realpython.com/python-news-december-2025/2025-12-08T14:00:00+00:00PEP 810 brings lazy imports to Python 3.15, PyPI tightens 2FA security, and Django 6.0 reaches release candidate. Catch up on all the important Python news!
<div><p>A lot happened last month in the world of Python! The core developers pushed ahead on <strong>Python 3.15</strong>, accepting <strong>PEP 810</strong> to bring explicit lazy imports to the language. PyPI tightened account security, <strong>Django 6.0</strong> landed with a slew of new features while celebrating twenty years of releases, and the <strong>Python Software Foundation (PSF)</strong> laid out its financial outlook and kicked off a year-end fundraiser.</p>
<p>Let’s dive into the biggest <strong>Python news</strong> from the past month!</p>
<div class="alert alert-warning" role="alert">
<p><strong markdown>Join Now:</strong> <a href="https://realpython.com/bonus/newsletter/" class="alert-link" data-toggle="modal" data-target="#modal-newsletter" markdown>Click here to join the Real Python Newsletter</a> and you’ll never miss another Python tutorial, course, or news update.</p>
</div>
<h2 id="python-releases-and-pep-highlights">Python Releases and PEP Highlights<a class="headerlink" href="#python-releases-and-pep-highlights" title="Permanent link"></a></h2>
<p>Last month brought forward movement on Python 3.15, with a new alpha release and a major <a href="/ref/glossary/pep/" class="ref-link">PEP</a> acceptance. Windows users also got an update to the new Python install manager that’s set to replace the traditional installers.</p>
<h3 id="python-3150-alpha-2-keeps-the-train-moving">Python 3.15.0 Alpha 2 Keeps the Train Moving<a class="headerlink" href="#python-3150-alpha-2-keeps-the-train-moving" title="Permanent link"></a></h3>
<p>Python 3.15’s second alpha, <a href="https://www.python.org/downloads/release/python-3150a2/">3.15.0a2</a>, arrived on November 19 as part of the language’s regular annual release cadence. It’s an early developer preview that isn’t intended for production, but it shows how 3.15 is shaping up and gives library authors something concrete to test against.</p>
<p>Like <a href="https://realpython.com/python-news-november-2025/#python-315-alpha-1-released">alpha 1</a>, this release is still relatively small in user-visible features, but it continues the work of:</p>
<ul>
<li>Making <strong>UTF-8 the default text encoding</strong> for files that don’t specify an encoding, via <a href="https://peps.python.org/pep-0686/">PEP 686</a></li>
<li>Providing a <strong>dedicated profiling API</strong> designed to work better with modern profilers and monitoring tools, via <a href="https://peps.python.org/pep-0799/">PEP 799</a></li>
<li>Exposing lower-level C APIs for creating <code>bytes</code> objects more efficiently, via <a href="https://peps.python.org/pep-0782/">PEP 782</a></li>
</ul>
<p>If you maintain packages, now is a good time to <a href="https://realpython.com/python-pre-release/">start running tests against the alphas</a> in a separate environment so you can catch regressions early.</p>
<p>You can always confirm which Python you’re running with <code>python -VV</code>:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="console" data-is-repl="true">
<div class="codeblock__header codeblock--yellow">
<span class="mr-2 noselect" aria-label="Language">Shell</span>
<div class="noselect">
<span class="codeblock__output-toggle" title="Toggle prompts and output" role="button"><span class="icon baseline js-codeblock-output-on codeblock__header--icon-lower" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#regular--rectangle-terminal"></use></svg></span></span>
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="gp">$ </span>python<span class="w"> </span>-VV
<span class="go">Python 3.15.0a2 (main, Nov 19 2025, 10:42:00) [GCC ...]</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>Just remember to keep the alpha builds isolated from your everyday projects!</p>
<h3 id="pep-810-accepted-explicit-lazy-imports">PEP 810 Accepted: Explicit Lazy Imports<a class="headerlink" href="#pep-810-accepted-explicit-lazy-imports" title="Permanent link"></a></h3>
<p>One of the month’s most consequential decisions for the language was the acceptance of <a href="https://peps.python.org/pep-0810/">PEP 810 – Explicit lazy imports</a>, which you may have read about in <a href="https://realpython.com/python-news-november-2025/#pep-810-drafted-explicit-lazy-imports">last month’s news</a>. The <a href="/ref/glossary/python-steering-council/" class="ref-link">Python Steering Council</a> accepted the proposal on November 3, only a month after its formal creation on October 2. With the PEP moving from <em>Draft</em> to <em>Accepted</em>, it’s now targeted for inclusion in Python 3.15!</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> One of the PEP’s authors, <a href="https://realpython.com/search?kind=podcast&q=pablo+galindo+salgado">Pablo Galindo Salgado</a>, has been a frequent guest on the <a href="https://realpython.com/podcasts/rpp/">Real Python Podcast</a>.</p>
</div>
<p>PEP 810 introduces new syntax for <a href="https://realpython.com/python-import/">imports</a> that are evaluated only when first used, rather than at module import time. At a high level, you’ll be able to write:</p>
<code-block class="mb-3" aria-label="Code block" data-syntax-language="python">
<div class="codeblock__header codeblock--blue">
<span class="mr-2 noselect" aria-label="Language">Python</span>
<div class="noselect">
</div>
</div>
<div class="codeblock__contents">
<div class="highlight highlight--with-header"><pre><span></span><code><span class="n">lazy</span> <span class="kn">import</span><span class="w"> </span><span class="nn">json</span>
<span class="k">def</span><span class="w"> </span><span class="nf">parse</span><span class="p">():</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span>
</code></pre></div>
<button class="codeblock__copy btn btn-outline-secondary border m-1 px-1 d-hover-only" title="Copy to clipboard"><span class="icon baseline" aria-hidden="true"><svg aria-hidden="true"><use href="/static/icons.5eccc70ec931.svg#@copy"></use></svg></span></button>
</div>
</code-block>
<p>In this example, Python loads the <code>json</code> module only if <code>parse()</code> runs.</p>
<p>The goals of explicit lazy imports are to:</p>
<ul>
<li><strong>Improve startup time</strong> for large applications with many rarely used imports</li>
<li><strong>Break tricky import cycles</strong> without resorting to local imports inside functions</li>
<li>Give frameworks and tools a <strong>clear, explicit way to defer expensive imports</strong></li>
</ul>
<p>Lazy imports are entirely opt-in, meaning that only imports marked as <code>lazy</code> change their behavior. The PEP is also careful to spell out how lazy modules interact with attributes like <a href="https://realpython.com/python-all-attribute/"><code>__all__</code></a>, <a href="/ref/glossary/exception/" class="ref-link">exception</a> reporting, and tools such as <a href="/ref/glossary/debugging/" class="ref-link">debuggers</a>.</p>
<div class="alert alert-primary" role="alert">
<p><strong>Note:</strong> The implementation work is still underway, so you won’t see the new syntax in 3.15.0a2 yet.</p>
</div>
<p>If you maintain a framework, CLI tool, or large application, it’s worth reading through the PEP and thinking about where lazy imports could simplify your startup path or trim cold-start latency.</p>
<h3 id="pythons-new-install-manager-moves-forward-on-windows">Python’s New Install Manager Moves Forward on Windows<a class="headerlink" href="#pythons-new-install-manager-moves-forward-on-windows" title="Permanent link"></a></h3>
</div><h2><a href="https://realpython.com/python-news-december-2025/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-news-december-2025/ »</a></h2>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #276: Exploring Quantum Computing & Python Frameworkshttps://realpython.com/podcasts/rpp/276/2025-12-05T12:00:00+00:00What are the recent advances in the field of quantum computing and high-performance computing? And what Python tools can you use to develop programs that run on quantum computers? This week on the show, Real Python author Negar Vahid discusses her tutorial, "Quantum Computing Basics With Qiskit."
<p>What are the recent advances in the field of quantum computing and high-performance computing? And what Python tools can you use to develop programs that run on quantum computers? This week on the show, Real Python author Negar Vahid discusses her tutorial, "Quantum Computing Basics With Qiskit."</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: How to Use Google's Gemini CLI for AI Code Assistancehttps://realpython.com/quizzes/how-to-use-gemini-cli/2025-12-03T12:00:00+00:00Learn how to install, authenticate, and safely use the Gemini CLI to interact with Google's Gemini models.
<p>In this quiz, you’ll test your understanding of the <a href="https://realpython.com/how-to-use-gemini-cli/">How to Use Google’s Gemini CLI for AI Code Assistance</a> tutorial.</p>
<p>By working through these questions, you’ll revisit how to install and verify prerequisites like Node.js, explore authentication options, and understand the CLI’s permission and safety model. You’ll also practice managing interactive sessions, enforcing stronger models, and approving or editing shell commands securely.</p>
<p>To deepen your understanding, review the sections on verifying your environment, authenticating safely, and running interactive prompts in the linked tutorial.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Introduction to pandashttps://realpython.com/courses/introduction-pandas/2025-12-02T14:00:00+00:00Learn pandas DataFrames: explore, clean, and visualize data with powerful tools for analysis. Delete unneeded data, import data from a CSV file, and more.
<p>The <a href="https://pandas.pydata.org/pandas-docs/stable/reference/frame.html">pandas DataFrame</a> is a <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html">structure</a> that contains <strong>two-dimensional data</strong> and its corresponding <strong>labels</strong>. DataFrames are widely used in <a href="https://realpython.com/tutorials/data-science/">data science</a>, <a href="https://realpython.com/tutorials/machine-learning/">machine learning</a>, scientific computing, and many other data-intensive fields.</p>
<p>DataFrames are similar to <a href="https://realpython.com/python-sql-libraries/">SQL tables</a> or the spreadsheets that you work with in Excel or Calc. In many cases, DataFrames are faster, easier to use, and more powerful than tables or spreadsheets because they’re an integral part of the <a href="https://www.python.org/about/">Python</a> and <a href="https://numpy.org/">NumPy</a> ecosystems.</p>
<p><strong>In this video course, you’ll learn:</strong></p>
<ul>
<li>What a <strong>pandas DataFrame</strong> is and how to create one</li>
<li>How to <strong>access, modify, add, sort, filter, and delete</strong> data</li>
<li>How to handle <strong>missing values</strong></li>
<li>How to work with <strong>time-series data</strong></li>
<li>How to quickly <strong>visualize</strong> data</li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Quiz: Quantum Computing Basics With Qiskithttps://realpython.com/quizzes/quantum-computing-basics/2025-12-01T12:00:00+00:00Test your understanding of quantum computing basics, including superposition, qubits, entanglement, and key programming concepts.
<p>Dive into quantum computing fundamentals with this quiz. You’ll practice key ideas like superposition, measurement, entanglement, and how quantum and classical systems work together. You’ll also revisit essential Qiskit commands and understand what limits today’s quantum computers.</p>
<p>Need a refresher? Check out <a href="https://realpython.com/quantum-computing-basics/">Quantum Computing Basics With Qiskit</a> for clear explanations and hands-on examples.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Getting Started With Claude Codehttps://realpython.com/courses/getting-started-claude-code/2025-11-25T14:00:00+00:00Learn to set up and use Claude Code for Python projects: install, run commands, and integrate with Git.
<p>Learn how to set up and start using Claude Code to boost your Python workflow. Learn how it differs from Claude Chat and how to use it effectively in your development setup.</p>
<p><strong>You’ll learn how to:</strong></p>
<ul>
<li>Install and configure Claude Code</li>
<li>Run it safely inside project directories</li>
<li>Work with CLAUDE.md for task context</li>
<li>Use Git integration for smoother coding workflows</li>
<li>Apply Claude Code to automate real programming tasks</li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #275: Building a FastAPI Application & Exploring Python Concurrencyhttps://realpython.com/podcasts/rpp/275/2025-11-21T12:00:00+00:00What are the steps to get started building a FastAPI application? What are the different types of concurrency available in Python? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.
<p>What are the steps to get started building a FastAPI application? What are the different types of concurrency available in Python? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Break Out of Loops With Python's break Keywordhttps://realpython.com/courses/break-out-of-loops-break-keyword/2025-11-18T14:00:00+00:00Learn how Python’s break lets you exit for and while loops early, with practical demos from simple games to everyday data tasks.
<p>In Python, the <a href="/ref/keywords/break/" class="ref-link"><code>break</code> statement</a> lets you exit a loop prematurely, transferring control to the code that follows the loop. This tutorial guides you through using <code>break</code> in both <code>for</code> and <code>while</code> loops. You’ll also briefly explore the <code>continue</code> keyword, which complements <code>break</code> by skipping the current loop iteration.</p>
<p><strong>By the end of this video course, you’ll understand that:</strong></p>
<ul>
<li><strong>A <code>break</code> in Python</strong> is a keyword that lets you exit a loop immediately, stopping further iterations.</li>
<li><strong>Using <code>break</code> outside of loops</strong> doesn’t make sense because it’s specifically designed to exit loops early.</li>
<li><strong>The <code>break</code> doesn’t exit all loops</strong>, only the innermost loop that contains it.</li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #274: Preparing Data Science Projects for Productionhttps://realpython.com/podcasts/rpp/274/2025-11-14T12:00:00+00:00How do you prepare your Python data science projects for production? What are the essential tools and techniques to make your code reproducible, organized, and testable? This week on the show, Khuyen Tran from CodeCut discusses her new book, "Production Ready Data Science."
<p>How do you prepare your Python data science projects for production? What are the essential tools and techniques to make your code reproducible, organized, and testable? This week on the show, Khuyen Tran from CodeCut discusses her new book, "Production Ready Data Science."</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Python Operators and Expressionshttps://realpython.com/courses/python-operators-expressions/2025-11-11T14:00:00+00:00Operators let you combine objects to create expressions that perform computations -- the core of how Python works.
<p>Python operators enable you to perform computations by combining objects and operators into expressions. Understanding Python operators is essential for manipulating data effectively.</p>
<p>This video course covers arithmetic, comparison, Boolean, identity, membership, bitwise, concatenation, and repetition operators, along with augmented assignment operators. You’ll also learn how to build expressions using these operators and explore operator precedence to understand the order of operations in complex expressions.</p>
<p><strong>By the end of this video course, you’ll understand that:</strong></p>
<ul>
<li><strong>Arithmetic operators</strong> perform mathematical calculations on numeric values.</li>
<li><strong>Comparison operators</strong> evaluate relationships between values, returning <strong>Boolean</strong> results.</li>
<li><strong>Boolean operators</strong> create compound logical expressions.</li>
<li><strong>Identity operators</strong> determine if two operands refer to the same object.</li>
<li><strong>Membership operators</strong> check for the presence of a value in a container.</li>
<li><strong>Bitwise operators</strong> manipulate data at the binary level.</li>
<li><strong>Concatenation and repetition operators</strong> manipulate sequence data types.</li>
<li><strong>Augmented assignment operators</strong> simplify expressions involving the same variable.</li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #273: Advice for Writing Maintainable Python Codehttps://realpython.com/podcasts/rpp/273/2025-11-07T12:00:00+00:00What are techniques for writing maintainable Python code? How do you make your Python more readable and easier to refactor? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.
<p>What are techniques for writing maintainable Python code? How do you make your Python more readable and easier to refactor? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
Building UIs in the Terminal With Python Textualhttps://realpython.com/courses/building-uis-terminal-python-textual/2025-11-04T14:00:00+00:00Learn to build rich, interactive terminal UIs in Python with Textual: a powerful library for modern, event-driven TUIs.
<p>Have you ever wanted to create an app with an appealing interface that works in the command line? Welcome to Textual, a Python toolkit and framework for creating beautiful, functional <strong>text-based user interface (TUI)</strong> applications. The Textual library provides a powerful and flexible framework for building TUIs. It offers a variety of features that allow you to create interactive and engaging console applications.</p>
<p>In this video course, you’ll learn how to create, style, and enhance Textual apps with layouts, events, and actions.</p>
<p><strong>By the end of this video course, you’ll understand that:</strong></p>
<ul>
<li><strong>Python Textual</strong> is a framework for building terminal-based applications with interactive and visually appealing text interfaces.</li>
<li><strong>Textual works</strong> by providing a set of widgets, layouts, and styling options, enabling you to create responsive and interactive console apps.</li>
<li>Textual is useful for building efficient, <strong>platform-independent text-based user interfaces</strong> that work over remote connections and in low-resource environments.</li>
</ul>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #272: Michael Kennedy: Managing Your Own Python Infrastructurehttps://realpython.com/podcasts/rpp/272/2025-10-31T12:00:00+00:00How do you deploy your Python application without getting locked into an expensive cloud-based service? This week on the show, Michael Kennedy from the Talk Python podcast returns to discuss his new book, "Talk Python in Production."
<p>How do you deploy your Python application without getting locked into an expensive cloud-based service? This week on the show, Michael Kennedy from the Talk Python podcast returns to discuss his new book, "Talk Python in Production."</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>
The Real Python Podcast – Episode #271: Benchmarking Python 3.14 & Enabling Asyncio to Scalehttps://realpython.com/podcasts/rpp/271/2025-10-24T12:00:00+00:00How does Python 3.14 perform under a few hand-crafted benchmarks? Does the performance of asyncio scale on the free-threaded build? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.
<p>How does Python 3.14 perform under a few hand-crafted benchmarks? Does the performance of asyncio scale on the free-threaded build? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.</p>
<hr />
<p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&utm_medium=rss&utm_campaign=footer">>> Click here to learn more and see examples</a> ]</em></p>