Real Python 2026-02-25T14:00:00+00:00 https://realpython.com/ Real Python How to Run Your Python Scripts and Code https://realpython.com/run-python-scripts/ 2026-02-25T14:00:00+00:00 Learn how to run Python scripts from the command line, REPL, IDEs, and file managers on Windows, Linux, and macOS. Master all execution approaches. <div><p>Running Python scripts is essential for executing your code. You can run Python scripts from the command line using <code>python script.py</code>, directly by making files executable with shebangs on Unix systems, or through IDEs and code editors. Python also supports interactive execution through the standard REPL for testing code snippets.</p> <p>This tutorial covers the most common practical approaches for running Python scripts across Windows, Linux, and macOS.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li>The <strong><code>python</code></strong> command followed by a <strong>script filename</strong> executes the code from the <strong>command line</strong> on all operating systems.</li> <li>Script mode runs code from <strong>files sequentially</strong>, while interactive mode uses the <strong>REPL</strong> for execution and testing with immediate feedback.</li> <li>Unix systems require <strong>executable permissions</strong> and a <strong>shebang line</strong> like <code>#!/usr/bin/env python3</code> to run scripts directly as programs.</li> <li>The <code>python</code> command’s <code>-m</code> option runs <strong>Python modules</strong> by searching <code>sys.path</code> rather than requiring file paths.</li> <li>IDEs like PyCharm and code editors like Visual Studio Code provide built-in options to <strong>run scripts</strong> from the environment interface.</li> </ul> <p>To get the most out of this tutorial, you should know the basics of working with your operating system’s <a href="https://realpython.com/terminal-commands/">terminal</a> and file manager. It’d also be beneficial to be familiar with a Python-friendly <a href="https://realpython.com/python-ides-code-editors-guide/">IDE or code editor</a> and with the standard Python <a href="https://realpython.com/python-repl/">REPL</a> (Read-Eval-Print Loop).</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Free Download:</strong> <a href="https://realpython.com/bonus/python-tricks-sample-pdf/" class="alert-link" data-toggle="modal" data-target="#modal-python-tricks-sample-pdf" markdown>Get a sample chapter from Python Tricks: The Book</a> that shows you Python’s best practices with simple examples you can apply instantly to write more beautiful + Pythonic code.</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.e98ec7a26cad.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “How to Run Your Python Scripts” 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/run-python-scripts/" 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: #e6c7ab;" alt="How to Run Your Python Scripts" src="https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/How-to-Run-A-Python-Script_Watermarked.65fe32bf5487.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.e98ec7a26cad.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/run-python-scripts/" class="stretched-link"><span class="my-0 h4">How to Run Your Python Scripts</span></a> <p class="text-muted mb-0 small">One of the most important skills you need to build as a Python developer is to be able to run Python scripts and code. Test your understanding on how good you are with running your code.</p> </div> </div> </div> <h2 id="what-scripts-and-modules-are">What Scripts and Modules Are<a class="headerlink" href="#what-scripts-and-modules-are" title="Permanent link"></a></h2> <p>In computing, the term <strong>script</strong> refers to a text file containing a logical sequence of orders that you can run to accomplish a specific task. These orders are typically expressed in a <a href="https://en.wikipedia.org/wiki/Scripting_language">scripting language</a>, which is a <a href="https://en.wikipedia.org/wiki/Programming_language">programming language</a> that allows you to manipulate, customize, and automate tasks.</p> <p>Scripting languages are usually <a href="https://en.wikipedia.org/wiki/Interpreter_(computing)">interpreted</a> at <a href="https://en.wikipedia.org/wiki/Runtime_(program_lifecycle_phase)">runtime</a> rather than <a href="https://en.wikipedia.org/wiki/Compiler">compiled</a>. So, scripts are typically run by an <a href="/ref/glossary/interpreter/" class="ref-link">interpreter</a>, which is responsible for executing each order in a sequence.</p> <p><a href="/ref/glossary/python/" class="ref-link">Python</a> is an interpreted language. Because of that, Python programs are commonly called scripts. However, this terminology isn’t completely accurate because Python programs can be way more complex than a simple, sequential script.</p> <p>In general, a <a href="/ref/glossary/text-file/" class="ref-link">file</a> containing executable Python <a href="/ref/glossary/source-code/" class="ref-link">code</a> is called a script—or an <strong>entry-point script</strong> in more complex applications—which is a common term for a top-level <strong>program</strong>. On the other hand, a file containing Python code that’s designed to be <a href="https://realpython.com/python-import/">imported</a> and used from another Python file is called a <a href="/ref/glossary/module/" class="ref-link"><strong>module</strong></a>.</p> <p>So, the main difference between a <a href="https://realpython.com/python-modules-packages/">module</a> and a script is that modules store <strong>importable code</strong> while scripts hold <strong>executable code</strong>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> Importable code is code that defines something but doesn’t perform a specific action. Some examples include <a href="/ref/glossary/function/" class="ref-link">function</a> and <a href="/ref/glossary/class/" class="ref-link">class</a> definitions. In contrast, executable code is code that performs specific actions. Some examples include <a href="https://realpython.com/defining-your-own-python-function/#calling-functions-in-python">function calls</a>, <a href="/ref/glossary/loop/" class="ref-link">loops</a>, and <a href="https://realpython.com/python-conditional-statements/">conditionals</a>.</p> </div> <p>In the following sections, you’ll learn how to run Python scripts, programs, and code in general. To kick things off, you’ll start by learning how to run them from your operating system’s command line or terminal.</p> <h2 id="how-to-run-python-scripts-from-the-command-line">How to Run Python Scripts From the Command Line<a class="headerlink" href="#how-to-run-python-scripts-from-the-command-line" title="Permanent link"></a></h2> <p>In Python programming, you’ll write programs in plain text files. By convention, files containing Python code use the <code>.py</code> extension, and there’s no distinction between scripts or executable programs and modules. All of them will use the same extension.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> On <a href="https://realpython.com/python-coding-setup-windows/">Windows</a> systems, the extension can also be <code>.pyw</code> for those applications that should use the <code>pythonw.exe</code> launcher.</p> </div> <p>To create a Python script, you can use any Python-friendly <a href="https://realpython.com/python-ides-code-editors-guide/">code editor or IDE</a> (integrated development environment). To keep moving forward in this tutorial, you’ll need to create a basic script, so fire up your favorite text editor and create a new <code>hello.py</code> file containing the following code:</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;">hello.py</code></span> <div class="noselect"> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="nb">print</span><span class="p">(</span><span class="s2">"Hello, World!"</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>This is the classic <code>"Hello, World!"</code> program in Python. The executable code consists of a call to the built-in <a href="https://realpython.com/python-print/"><code>print()</code></a> function that displays the <code>"Hello, World!"</code> message on your screen.</p> <p>With this small program in place, you’re ready to learn different ways to run it. You’ll start by running the program from your command line, which is arguably the most commonly used approach to running scripts.</p> <h3 id="using-the-python-command">Using the <code>python</code> Command<a class="headerlink" href="#using-the-python-command" title="Permanent link"></a></h3> <p>To run Python scripts with the <code>python</code> command, you need to open a command-line window and type in the word <code>python</code> followed by the path to your target script:</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.e98ec7a26cad.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.e98ec7a26cad.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.e98ec7a26cad.svg#v4--apple"></use></svg></span>Linux + macOS</a> </li> </ul> </div><h2><a href="https://realpython.com/run-python-scripts/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/run-python-scripts/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Start Building With FastAPI https://realpython.com/courses/start-building-with-fastapi/ 2026-02-24T14:00:00+00:00 Learn how to build APIs with FastAPI in Python, including Pydantic models, HTTP methods, CRUD operations, and interactive documentation. <p>FastAPI is a web framework for building APIs with Python. It leverages standard Python type hints to provide automatic validation, serialization, and interactive documentation. When you&rsquo;re deciding between Python web frameworks, FastAPI stands out for its speed, developer experience, and built-in features that reduce boilerplate code for API development:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th class="text-center">Pick FastAPI</th> <th class="text-center">Pick Flask or Django</th> </tr> </thead> <tbody> <tr> <td>You want to build an API-driven web app</td> <td class="text-center">✅</td> <td class="text-center">—</td> </tr> <tr> <td>You need a full-stack web framework</td> <td class="text-center">—</td> <td class="text-center">✅</td> </tr> <tr> <td>You value automatic API documentation</td> <td class="text-center">✅</td> <td class="text-center">—</td> </tr> </tbody> </table> </div> <p>Whether you&rsquo;re building a minimal <a href="https://realpython.com/api-integration-in-python/">REST API</a> or a complex backend service, understanding core features of <a href="https://fastapi.tiangolo.com/">FastAPI</a> will help you make an informed decision about adopting it for your projects. To get the most from this video course, you&rsquo;ll benefit from having basic knowledge of Python <a href="https://realpython.com/defining-your-own-python-function/">functions</a>, <a href="https://realpython.com/python-requests/">HTTP concepts</a>, and <a href="https://realpython.com/python-json/">JSON</a> handling.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Python for Loops: The Pythonic Way https://realpython.com/python-for-loop/ 2026-02-23T14:00:00+00:00 Learn how to use Python for loops to iterate over lists, tuples, strings, and dictionaries with Pythonic looping techniques. <div><p>Python’s <code>for</code> loop allows you to iterate over the items in a collection, such as lists, tuples, strings, and dictionaries. The <code>for</code> loop syntax declares a loop variable that takes each item from the collection in each iteration. This loop is ideal for repeatedly executing a block of code on each item in the collection. You can also tweak <code>for</code> loops further with features like <code>break</code>, <code>continue</code>, and <code>else</code>.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li><strong>Python’s <code>for</code> loop</strong> iterates over items in a data collection, allowing you to execute code for each item.</li> <li>To <strong>iterate from <code>0</code> to <code>10</code></strong>, you use the <code>for index in range(11):</code> construct.</li> <li>To <strong>repeat code a number of times</strong> without processing the data of an iterable, use the <code>for _ in range(times):</code> construct.</li> <li>To do <strong>index-based iteration</strong>, you can use <code>for index, value in enumerate(iterable):</code> to access both index and item.</li> </ul> <p>In this tutorial, you’ll gain practical knowledge of using <code>for</code> loops to traverse various collections and learn Pythonic looping techniques. You’ll also learn how to handle exceptions and use asynchronous iterations to make your Python code more robust and efficient.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/python-for-loop-code/" class="alert-link" data-toggle="modal" data-target="#modal-python-for-loop-code" markdown>Click here to download the free sample code</a> that shows you how to use for loops 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.e98ec7a26cad.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “Python for Loops: The Pythonic Way” 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-for-loop/" 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="Python for Loops: The Pythonic Way" src="https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/UPDATE-Python-for-Loops-Definite-Iteration_Watermarked.32bfd8825dfe.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.e98ec7a26cad.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-for-loop/" class="stretched-link"><span class="my-0 h4">Python for Loops: The Pythonic Way</span></a> <p class="text-muted mb-0 small">In this quiz, you'll test your understanding of Python's for loop. You'll revisit how to iterate over items in a data collection, how to use range() for a predefined number of iterations, and how to use enumerate() for index-based iteration.</p> </div> </div> </div> <h2 id="getting-started-with-the-python-for-loop">Getting Started With the Python <code>for</code> Loop<a class="headerlink" href="#getting-started-with-the-python-for-loop" title="Permanent link"></a></h2> <p>In programming, <a href="/ref/glossary/loop/" class="ref-link"><strong>loops</strong></a> are <a href="https://realpython.com/python-control-flow/">control flow</a> <a href="/ref/glossary/statement/" class="ref-link">statements</a> that allow you to repeat a given set of operations a number of times. In practice, you’ll find two main types of loops:</p> <ol> <li><a href="https://en.wikipedia.org/wiki/For_loop"><code>for</code> loops</a> are mostly used to iterate a <em>known</em> number of times, which is common when you’re processing data <a href="/ref/glossary/collection/" class="ref-link">collections</a> with a specific number of data items.</li> <li><a href="https://realpython.com/python-while-loop/"><code>while</code> loops</a> are commonly used to iterate an <em>unknown</em> number of times, which is useful when the number of <a href="/ref/glossary/iteration/" class="ref-link">iterations</a> depends on a given condition.</li> </ol> <p>Python has both of these loops and in this tutorial, you’ll learn about <strong><code>for</code> loops</strong>. In Python, you’ll generally use <code>for</code> loops when you need to iterate over the items in a data collection. This type of loop lets you traverse different data collections and run a specific group of statements <em>on</em> or <em>with</em> each item in the input collection.</p> <p>In Python, <code>for</code> loops are <a href="https://docs.python.org/3/reference/compound_stmts.html">compound statements</a> with a <em>header</em> and a <em>code block</em> that runs a predefined number of times. The basic syntax of a <code>for</code> loop is shown below:</p> <code-block class="mb-3" aria-label="Code block" data-syntax-language="python_syntax"> <div class="codeblock__header codeblock--blue"> <span class="mr-2 noselect" aria-label="Language">Python Syntax</span> <div class="noselect"> </div> </div> <div class="codeblock__contents"> <div class="highlight highlight--with-header"><pre><span></span><code><span class="k">for</span> <span class="n">variable</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">body</span><span class="o">&gt;</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>In this syntax, <code>variable</code> is the loop <a href="/ref/glossary/variable/" class="ref-link">variable</a>. In each iteration, this variable takes the value of the current item in <code>iterable</code>, which represents the data collection you need to iterate over. The loop body can consist of one or more statements that must be indented properly.</p> <p>Here’s a more detailed breakdown of this syntax:</p> <ul> <li><strong><code>for</code></strong> is the keyword that initiates the loop header.</li> <li><strong><code>variable</code></strong> is a variable that holds the current item in the input <a href="/ref/glossary/iterable/" class="ref-link">iterable</a>.</li> <li><strong><code>in</code></strong> is a keyword that connects the loop variable with the iterable.</li> <li><strong><code>iterable</code></strong> is a data collection that can be iterated over.</li> <li><strong><code>&lt;body&gt;</code></strong> consists of one or more statements to execute in each iteration.</li> </ul> <p>Here’s a quick example of how you can use a <code>for</code> loop to iterate over a <a href="/ref/builtin-types/list/" class="ref-link"><code>list</code></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.e98ec7a26cad.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">&gt;&gt;&gt; </span><span class="n">colors</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"red"</span><span class="p">,</span> <span class="s2">"green"</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">,</span> <span class="s2">"yellow"</span><span class="p">]</span> <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">color</span> <span class="ow">in</span> <span class="n">colors</span><span class="p">:</span> <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">color</span><span class="p">)</span> <span class="gp">...</span> <span class="go">red</span> <span class="go">green</span> <span class="go">blue</span> <span class="go">yellow</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>In this example, <code>color</code> is the loop variable, while the <code>colors</code> list is the target collection. Each time through the loop, <code>color</code> takes on a successive item from <code>colors</code>. In this loop, the body consists of a call to <a href="https://realpython.com/python-print/"><code>print()</code></a> that displays the value on the screen. This loop runs once for each item in the target iterable. The way the code above is written is the <a href="https://realpython.com/learning-paths/writing-pythonic-code/">Pythonic</a> way to write it.</p> <p>However, what’s an <a href="https://realpython.com/python-iterators-iterables/#getting-to-know-python-iterables">iterable</a> anyway? In Python, an <strong>iterable</strong> is an object—often a data collection—that can be iterated over. Common examples of iterables in Python include <a href="https://realpython.com/python-list/">lists</a>, <a href="https://realpython.com/python-tuple/">tuples</a>, <a href="https://realpython.com/python-strings/">strings</a>, <a href="https://realpython.com/python-dicts/">dictionaries</a>, and <a href="https://realpython.com/python-sets/">sets</a>, which are all built-in data types. You can also have custom classes that support iteration.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> Python has both iterables and iterators. Iterables support the <strong>iterable protocol</strong> consisting of the <code>.__iter__()</code> <a href="https://realpython.com/python-magic-methods/">special method</a>. Similarly, iterators support the <strong>iterator protocol</strong> that’s based on the <code>.__iter__()</code> and <code>.__next__()</code> special methods.</p> <p>Both iterables and iterators can be iterated over. All iterators are iterables, but not all iterables are iterators. Python iterators play a fundamental role in <code>for</code> loops because they drive the iteration process.</p> <p>A deeper discussion on iterables and iterators is beyond the scope of this tutorial. However, to learn more about them, check out the <a href="https://realpython.com/python-iterators-iterables/">Iterators and Iterables in Python: Run Efficient Iterations</a> tutorial.</p> </div> <p>You can also have a loop with multiple loop variables:</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.e98ec7a26cad.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">&gt;&gt;&gt; </span><span class="n">points</span> <span class="o">=</span> <span class="p">[(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">),</span> <span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">3</span><span class="p">)]</span> <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">points</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">"</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="si">= }</span><span class="s2"> and </span><span class="si">{</span><span class="n">y</span><span class="w"> </span><span class="si">= }</span><span class="s2">"</span><span class="p">)</span> <span class="gp">...</span> <span class="go">x = 1 and y = 4</span> <span class="go">x = 3 and y = 6</span> <span class="go">x = 7 and y = 3</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>In this loop, you have two loop variables, <code>x</code> and <code>y</code>. Note that to use this syntax, you just need to provide a tuple of loop variables. Also, you can have as many loop variables as you need as long as you have the correct number of items to <a href="https://realpython.com/python-tuple/#packing-and-unpacking-tuples">unpack</a> into them. You’ll also find this pattern useful when iterating over <a href="#collections-dictionaries-and-sets">dictionary</a> items or when you need to do <a href="#looping-over-several-iterables-in-parallel">parallel iteration</a>.</p> <p>Sometimes, the input iterable may be empty. In that case, the loop will run its header once but won’t execute its body:</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.e98ec7a26cad.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">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="p">[]:</span> <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="gp">...</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> </div><h2><a href="https://realpython.com/python-for-loop/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-for-loop/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Build a Hash Table in Python With TDD https://realpython.com/quizzes/python-hash-table/ 2026-02-23T12:00:00+00:00 Learn how Python hashing spreads values into buckets and powers hash tables. Practice collisions, uniform distribution, and test-driven development. <p>In this quiz, you&rsquo;ll review hash functions, collision resolution strategies, hash function distribution, the avalanche effect, and key principles of Test-Driven Development.</p> <p>For more practice and context, explore <a href="https://realpython.com/python-hash-table/">Build a Hash Table in Python With TDD</a>.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #285: Exploring MCP Apps & Adding Interactive UIs to Clients https://realpython.com/podcasts/rpp/285/ 2026-02-20T12:00:00+00:00 How can you move your MCP tools beyond plain text? How do you add interactive UI components directly inside chat conversations? This week on the show, Den Delimarsky from Anthropic joins us to discuss MCP Apps and interactive UIs in MCP. <p>How can you move your MCP tools beyond plain text? How do you add interactive UI components directly inside chat conversations? This week on the show, Den Delimarsky from Anthropic joins us to discuss MCP Apps and interactive UIs in MCP.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Python's tuple Data Type: A Deep Dive With Examples https://realpython.com/quizzes/python-tuple/ 2026-02-19T12:00:00+00:00 Practice Python tuples: create, access, and unpack immutable sequences to write safer, clearer code. Reinforce basics and avoid common gotchas. Try the quiz. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/python-tuple/">Python tuples</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit various ways to interact with Python tuples. You&rsquo;ll also practice recognizing common features and gotchas.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> How to Install Python on Your System: A Guide https://realpython.com/installing-python/ 2026-02-18T14:00:00+00:00 Learn how to install the latest Python version on Windows, macOS, and Linux. Check your version and choose the best installation method for your system. <div><p>To learn how to install Python on your system, you can follow a few straightforward steps. First, check if Python is already installed by opening a command-line interface and typing <code>python --version</code> or <code>python3 --version</code>.</p> <p>You can install Python on Windows using the official installer from Python.org or through the Microsoft Store. On macOS, you can use the official installer or Homebrew. For Linux, use your package manager or build Python from source.</p> <p><strong>By the end of this tutorial, you’ll understand how to:</strong></p> <ul> <li><strong>Check if Python is installed</strong> by running <code>python --version</code> or <code>python3 --version</code> in a command-line interface.</li> <li><strong>Upgrade Python</strong> by downloading and installing the latest version from Python.org.</li> <li><strong>Install and manage multiple Python versions</strong> with <code>pyenv</code> to keep them separate.</li> </ul> <p>This tutorial covers installing the latest Python on the most important platforms or operating systems, such as Windows, macOS, Linux, iOS, and Android. However, it doesn’t cover all the existing Linux distributions, as that would be a massive task. Nevertheless, you’ll find instructions for the most popular distributions available today.</p> <p>To get the most out of this tutorial, you should be comfortable using your operating system’s <a href="https://realpython.com/terminal-commands/">terminal</a> or command line.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Free Bonus:</strong> <a href="https://realpython.com/bonus/python-cheat-sheet-shortened/" class="alert-link" data-toggle="modal" data-target="#modal-python-cheat-sheet-shortened" markdown>Click here to get a Python Cheat Sheet</a> and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.</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.e98ec7a26cad.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “How to Install Python on Your System: A Guide” 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-installation-and-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: #b9abe6;" alt="Python 3 Installation &amp; Setup Guide" src="https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Python-3-Installation--Setup-Guide_Watermarked.62f654dcab67.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.e98ec7a26cad.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-installation-and-setup/" class="stretched-link"><span class="my-0 h4">How to Install Python on Your System: A Guide</span></a> <p class="text-muted mb-0 small">In this quiz, you'll test your understanding of how to install or update Python on your computer. With this knowledge, you'll be able to set up Python on various operating systems, including Windows, macOS, and Linux.</p> </div> </div> </div> <h2 id="windows-how-to-check-or-get-python">Windows: How to Check or Get Python<a class="headerlink" href="#windows-how-to-check-or-get-python" title="Permanent link"></a></h2> <p>In this section, you’ll learn to check whether Python is installed on your Windows operating system (OS) and which version you have. You’ll also explore three installation options that you can use on Windows.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> In this tutorial, you’ll focus on installing the latest version of Python in your current operating system (OS) rather than on installing multiple versions of Python. If you want to install several versions of Python in your OS, then check out the <a href="https://realpython.com/intro-to-pyenv/">Managing Multiple Python Versions With <code>pyenv</code></a> tutorial. Note that on Windows machines, you’d have to use <a href="https://github.com/pyenv-win/pyenv-win"><code>pyenv-win</code></a> instead of <code>pyenv</code>.</p> </div> <p>For a more comprehensive guide on setting up a Windows machine for Python programming, check out <a href="https://realpython.com/python-coding-setup-windows/">Your Python Coding Environment on Windows: Setup Guide</a>.</p> <h3 id="checking-the-python-version-on-windows">Checking the Python Version on Windows<a class="headerlink" href="#checking-the-python-version-on-windows" title="Permanent link"></a></h3> <p>To check whether you already have Python on your Windows machine, open a command-line application like <a href="https://realpython.com/python-coding-setup-windows/#installing-powershell-core">PowerShell</a> or the <a href="https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab">Windows Terminal</a>.</p> <p>Follow the steps below to open PowerShell on Windows:</p> <ol> <li>Press the <span class="keys"><kbd class="key-windows">Win</kbd></span> key.</li> <li>Type <code>PowerShell</code>.</li> <li>Press <span class="keys"><kbd class="key-enter">Enter</kbd></span>.</li> </ol> <p>Alternatively, you can right-click the <em>Start</em> button and select <em>Windows PowerShell</em> or <em>Windows PowerShell (Admin)</em>. In some versions of Windows, you’ll find <em>Terminal</em> or <em>Terminal (admin)</em>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> To learn more about your options for the Windows terminal, check out <a href="https://realpython.com/python-coding-setup-windows/">Your Python Coding Environment on Windows: Setup Guide</a>.</p> </div> <p>With the command line open, type in the following command and press the <span class="keys"><kbd class="key-enter">Enter</kbd></span> key:</p> <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.e98ec7a26cad.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&gt; </span><span class="n">python</span> <span class="p">-</span><span class="n">-version</span> <span class="go">Python 3.x.z</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Using the <code>--version</code> switch will show you the installed version. Note that the <code>3.x.z</code> part is a placeholder here. In your machine, <code>x</code> and <code>z</code> will be numbers corresponding to the specific version you have installed.</p> <p>Alternatively, you can use the <code>-V</code> switch:</p> <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.e98ec7a26cad.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&gt; </span><span class="n">python</span> <span class="n">-V</span> <span class="go">Python 3.x.z</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>You can also use the <code>py</code> launcher, which is the Python launcher for Windows and is especially helpful if you plan to work with multiple Python versions:</p> <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.e98ec7a26cad.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&gt; </span><span class="n">py</span> <span class="p">-</span><span class="n">-version</span> <span class="go">Python 3.x.z</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> </div><h2><a href="https://realpython.com/installing-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/installing-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: How to Install Python on Your System: A Guide https://realpython.com/quizzes/python-installation-and-setup/ 2026-02-18T12:00:00+00:00 In this quiz, you'll test your understanding of how to install or update Python on your computer. With this knowledge, you'll be able to set up Python on various operating systems, including Windows, macOS, and Linux. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/installing-python/">how to install Python</a>. This quiz covers questions about how to check which version of Python is installed on your machine, and how you can install or update Python on various operating systems.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Write Python Docstrings Effectively https://realpython.com/courses/write-python-docstrings-effectively/ 2026-02-17T14:00:00+00:00 Learn to write clear, effective Python docstrings using best practices, common styles, and built-in conventions for your code. <p>Writing clear, consistent docstrings in Python helps others understand your code&rsquo;s purpose, parameters, and outputs. In this video course, you&rsquo;ll learn about best practices, standard formats, and common pitfalls to avoid, ensuring your documentation is accessible to users and tools alike.</p> <p><strong>By the end of this video course, you&rsquo;ll understand that:</strong></p> <ul> <li>Docstrings are strings used to <strong>document your Python code</strong> and can be accessed at runtime.</li> <li>Python <strong>comments and docstrings</strong> have important differences.</li> <li><strong>One-line</strong> and <strong>multiline docstrings</strong> are classifications of docstrings.</li> <li>Common docstring formats include <strong>reStructuredText</strong>, <strong>Google-style</strong>, <strong>NumPy-style</strong>, and <strong>doctest-style</strong>.</li> <li><strong>Antipatterns</strong> such as inconsistent formatting <strong>should be avoided</strong> when writing docstrings.</li> </ul> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> TinyDB: A Lightweight JSON Database for Small Projects https://realpython.com/tinydb-python/ 2026-02-16T14:00:00+00:00 If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be exactly what you need. <div><p>TinyDB is a Python implementation of a NoSQL, document-oriented database. Unlike a traditional relational database, which stores records across multiple linked tables, a document-oriented database stores its information as separate documents in a key-value structure. The keys are similar to the field headings, or attributes, in a relational database table, while the values are similar to the table’s attribute values.</p> <p>TinyDB uses the familiar Python <strong>dictionary</strong> for its document structure and stores its documents in a <strong>JSON file</strong>.</p> <p>TinyDB is written in Python, making it easily extensible and customizable, with no external dependencies or server setup needed. Despite its small footprint, it still fully supports the familiar database <a href="https://realpython.com/crud-operations/">CRUD features</a> of creating, reading, updating, and deleting documents using an <a href="/ref/glossary/api/" class="ref-link">API</a> that’s logical to use.</p> <p>The table below will help you decide whether TinyDB is a good fit for your use case:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th class="text-center">TinyDB</th> <th>Possible Alternatives</th> </tr> </thead> <tbody> <tr> <td>Local, small dataset, single-process use (scripts, <a href="https://realpython.com/command-line-interfaces-python-argparse/">CLIs</a>, prototypes)</td> <td class="text-center">✅</td> <td><a href="https://github.com/Milkman337/simpleJDB/">simpleJDB</a>, Python’s <a href="https://realpython.com/python-json/"><code>json</code> module</a>, <a href="https://realpython.com/python-sqlite-sqlalchemy/">SQLite</a></td> </tr> <tr> <td>Local use that requires SQL, constraints, joins, or stronger durability</td> <td class="text-center">—</td> <td>SQLite, <a href="https://realpython.com/python-sql-libraries/">PostgreSQL</a></td> </tr> <tr> <td>Multi-user, multi-process, distributed, or production-scale systems</td> <td class="text-center">—</td> <td>PostgreSQL, <a href="https://realpython.com/python-mysql/">MySQL</a>, <a href="https://realpython.com/introduction-to-mongodb-and-python/">MongoDB</a></td> </tr> </tbody> </table> </div> <p>Whether you’re looking to use a small NoSQL database in one of your projects or you’re just curious how a lightweight database like TinyDB works, this tutorial is for you. By the end, you’ll have a clear sense of when TinyDB shines, and when it’s better to reach for something else.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/tinydb-python-code/" class="alert-link" data-toggle="modal" data-target="#modal-tinydb-python-code" markdown>Click here to download the free sample code</a> you’ll use in this tutorial to explore TinyDB.</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.e98ec7a26cad.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “TinyDB: A Lightweight JSON Database for Small Projects” 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/tinydb-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: #b9abe6;" alt="TinyDB: A Lightweight JSON Database for Small Projects" src="https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/TinyDB_Watermarked.d62532b57253.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.e98ec7a26cad.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/tinydb-python/" class="stretched-link"><span class="my-0 h4">TinyDB: A Lightweight JSON Database for Small Projects</span></a> <p class="text-muted mb-0 small">If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be what you need.</p> </div> </div> </div> <h2 id="get-ready-to-explore-tinydb">Get Ready to Explore TinyDB<a class="headerlink" href="#get-ready-to-explore-tinydb" title="Permanent link"></a></h2> <p>TinyDB is a standalone library, meaning it doesn’t rely on any other libraries to work. You’ll need to install it, though.</p> <p>You’ll also use the <a href="https://realpython.com/python-pretty-print/"><code>pprint</code></a> module to format <a href="https://realpython.com/python-dicts/">dictionary</a> documents for easier reading, and Python’s <a href="/ref/stdlib/csv/" class="ref-link"><code>csv</code></a> module to work with <a href="https://realpython.com/python-interview-problem-parsing-csv-files/">CSV</a> files. You don’t need to install either of these because they’re included in Python’s <a href="/ref/glossary/standard-library/" class="ref-link">standard library</a>.</p> <p>So to follow along, you only need to install the TinyDB library in your environment. First, <a href="https://realpython.com/python-virtual-environments-a-primer/">create and activate a virtual environment</a>, then install the library using <a href="/ref/glossary/pip/" class="ref-link"><code>pip</code></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.e98ec7a26cad.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>tinydb </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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Alternatively, you could set up a small <a href="https://realpython.com/python-pyproject-toml/"><code>pyproject.toml</code> file</a> and <a href="https://realpython.com/python-uv/">manage your dependencies using <code>uv</code></a>.</p> <p>When you add documents to your database, you often do so manually by creating Python dictionaries. In this tutorial, you’ll do this, and also learn how to work with documents already stored in a <a href="https://realpython.com/python-json/">JSON</a> file. You’ll even learn how to add documents from data stored in a CSV file.</p> <p>These files will be highlighted as needed and are available in this tutorial’s downloads. You might want to download them to your program folder before you start to keep them handy:</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/tinydb-python-code/" class="alert-link" data-toggle="modal" data-target="#modal-tinydb-python-code" markdown>Click here to download the free sample code</a> you’ll use in this tutorial to explore TinyDB.</p> </div> <p>Regardless of the files you use or the documents you create manually, they all rely on the same world population data. Each document will contain up to six fields, which become the dictionary keys used when the associated values are added to your database:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Field</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>continent</code></td> <td>The continent the country belongs to</td> </tr> <tr> <td><code>location</code></td> <td>Country</td> </tr> <tr> <td><code>date</code></td> <td>Date population count made</td> </tr> <tr> <td><code>% of world</code></td> <td>Percentage of the world’s population</td> </tr> <tr> <td><code>population</code></td> <td>Population</td> </tr> <tr> <td><code>source</code></td> <td>Source of population</td> </tr> </tbody> </table> </div> <p>As mentioned earlier, the four primary database operations are <strong>C</strong>reate, <strong>R</strong>ead, <strong>U</strong>pdate, and <strong>D</strong>elete—collectively known as the <a href="https://realpython.com/crud-operations/">CRUD operations</a>. In the next section, you’ll learn how you can perform each of them.</p> <p>To begin with, you’ll explore the <em>C</em> in CRUD. It’s time to get creative.</p> <h2 id="create-your-database-and-documents">Create Your Database and Documents<a class="headerlink" href="#create-your-database-and-documents" title="Permanent link"></a></h2> <p>The first thing you’ll do is <strong>create</strong> a new database and add some documents to it. To do this, you create a <code>TinyDB()</code> <a href="/ref/glossary/object/" class="ref-link">object</a> that includes the name of a JSON file to store your data. Any documents you add to the database are then saved in that file.</p> <p>Documents in TinyDB are stored in tables. Although it’s not necessary to create a table manually, doing so can help you organize your documents, especially when working with multiple tables.</p> <p>To start, you create a script named <code>create_db.py</code> that initializes your first database and adds documents in several different ways. The first part of your script looks like this:</p> </div><h2><a href="https://realpython.com/tinydb-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/tinydb-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: TinyDB: A Lightweight JSON Database for Small Projects https://realpython.com/quizzes/tinydb-python/ 2026-02-16T12:00:00+00:00 If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be what you need. <p>In this quiz, you&rsquo;ll test your understanding of the TinyDB database library and what it has to offer, and you&rsquo;ll revisit many of the concepts from the <a href="https://realpython.com/tinydb-python/">TinyDB: A Lightweight JSON Database for Small Projects</a> tutorial.</p> <p>Remember that the <a href="https://tinydb.readthedocs.io/en/latest/index.html">official documentation</a> is also a great reference.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #284: Running Local LLMs With Ollama and Connecting With Python https://realpython.com/podcasts/rpp/284/ 2026-02-13T12:00:00+00:00 Would you like to learn how to work with LLMs locally on your own computer? How do you integrate your Python projects with a local model? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects. <p>Would you like to learn how to work with LLMs locally on your own computer? How do you integrate your Python projects with a local model? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Python's list Data Type: A Deep Dive With Examples https://realpython.com/quizzes/python-list/ 2026-02-12T12:00:00+00:00 Check your Python list skills with quick tasks on indexing, slicing, methods, copies, comprehensions, and pitfalls. <p>Get hands-on with Python lists in this quick quiz. You&rsquo;ll revisit indexing and slicing, update items in place, and compare list methods.</p> <p>Along the way, you&rsquo;ll look at reversing elements, using the <code>list()</code> constructor and the <code>len()</code> function, and distinguishing between shallow and deep copies. For a refresher, see the Real Python guide to <a href="https://realpython.com/python-list/">Python lists</a>.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> What Exactly Is the Zen of Python? https://realpython.com/zen-of-python/ 2026-02-11T14:00:00+00:00 The Zen of Python is a collection of 19 guiding principles for writing good Python code. Learn its history, meaning, and hidden jokes. <div><p>The <strong>Zen of Python</strong> is a collection of 19 aphorisms that capture the guiding principles behind Python’s design. You can display them anytime by running <code>import this</code> in a Python REPL. Tim Peters wrote them in 1999 as a joke, but they became an iconic part of Python culture that was even formalized as <a href="/ref/glossary/pep/" class="ref-link">PEP</a> 20.</p> <p><strong>By the end of this tutorial, you’ll understand:</strong></p> <ul> <li>The Zen of Python is a <strong>humorous poem</strong> of 19 aphorisms describing Python’s design philosophy</li> <li>Running <code>import this</code> in a Python <a href="/ref/glossary/interpreter/" class="ref-link">interpreter</a> displays the <strong>complete text</strong> of the Zen of Python</li> <li><strong>Tim Peters</strong> wrote the Zen of Python in 1999 as a tongue-in-cheek comment on a mailing list</li> <li>The aphorisms are <strong>guidelines, not strict rules</strong>, and some intentionally contradict each other</li> <li>The principles promote <strong>readability, simplicity, and explicitness</strong> while acknowledging that practicality matters</li> </ul> <p>Experienced Pythonistas often refer to the Zen of Python as a source of wisdom and guidance, especially when they want to settle an argument about certain design decisions in a piece of code. In this tutorial, you’ll explore the origins of the Zen of Python, learn how to interpret its mysterious aphorisms, and discover the Easter eggs hidden within it.</p> <p>You don’t need to be a Python master to understand the Zen of Python! But you do need to answer an important question: <strong>What exactly is the Zen of Python?</strong></p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Free Bonus:</strong> <a href="https://realpython.com/bonus/python-easter-eggs/" class="alert-link" data-toggle="modal" data-target="#modal-python-easter-eggs" markdown>Click here to download your Easter egg hunt</a> to discover what’s hidden inside 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.e98ec7a26cad.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “What Exactly Is the Zen of 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/zen-of-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: #b9abe6;" alt="What's the Zen of Python?" src="https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/Whats-the-Zen-of-Python_Watermarked.3ec4785e1bb9.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.e98ec7a26cad.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/zen-of-python/" class="stretched-link"><span class="my-0 h4">What Exactly Is the Zen of Python?</span></a> <p class="text-muted mb-0 small">Learn and test the Zen of Python, its guiding aphorisms, and tips for writing clearer, more readable, and maintainable code.</p> </div> </div> </div> <h2 id="in-short-its-a-humorous-poem-listing-python-philosophies">In Short: It’s a Humorous Poem Listing Python Philosophies<a class="headerlink" href="#in-short-its-a-humorous-poem-listing-python-philosophies" title="Permanent link"></a></h2> <p>According to the <a href="https://docs.python.org/3/glossary.html">Python glossary</a>, which contains definitions of popular terms related to this programming language, the <strong>Zen of Python</strong> is a:</p> <blockquote> <p>Listing of Python design principles and philosophies that are helpful in understanding and using the language. The listing can be found by typing “<code>import this</code>” at the interactive prompt. (<a href="https://docs.python.org/3/glossary.html#term-Zen-of-Python">Source</a>)</p> </blockquote> <p>Indeed, when you type the indicated <a href="https://realpython.com/python-import/"><code>import</code> statement</a> into an interactive <a href="https://realpython.com/python-repl/">Python REPL</a>, then you’ll be presented with the nineteen aphorisms that make up the Zen of 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.e98ec7a26cad.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">&gt;&gt;&gt; </span><span class="kn">import</span><span class="w"> </span><span class="nn">this</span> <span class="go">The Zen of Python, by Tim Peters</span> <span class="go">Beautiful is better than ugly.</span> <span class="go">Explicit is better than implicit.</span> <span class="go">Simple is better than complex.</span> <span class="go">Complex is better than complicated.</span> <span class="go">Flat is better than nested.</span> <span class="go">Sparse is better than dense.</span> <span class="go">Readability counts.</span> <span class="go">Special cases aren't special enough to break the rules.</span> <span class="go">Although practicality beats purity.</span> <span class="go">Errors should never pass silently.</span> <span class="go">Unless explicitly silenced.</span> <span class="go">In the face of ambiguity, refuse the temptation to guess.</span> <span class="go">There should be one-- and preferably only one --obvious way to do it.</span> <span class="go">Although that way may not be obvious at first unless you're Dutch.</span> <span class="go">Now is better than never.</span> <span class="go">Although never is often better than *right* now.</span> <span class="go">If the implementation is hard to explain, it's a bad idea.</span> <span class="go">If the implementation is easy to explain, it may be a good idea.</span> <span class="go">Namespaces are one honking great idea -- let's do more of those!</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>The byline reveals the poem’s author, <a href="https://en.wikipedia.org/wiki/Tim_Peters_(software_engineer)">Tim Peters</a>, who’s a renowned software engineer and a long-standing <a href="https://realpython.com/cpython-source-code-guide/">CPython</a> core developer best known for inventing the <a href="https://realpython.com/sorting-algorithms-python/#the-timsort-algorithm-in-python">Timsort</a> sorting algorithm. He also authored the <a href="https://realpython.com/python-doctest/"><code>doctest</code></a> and <a href="https://realpython.com/python-timer/#estimating-running-time-with-timeit"><code>timeit</code></a> modules in the Python <a href="/ref/glossary/standard-library/" class="ref-link">standard library</a>, along with making many other contributions.</p> <p>Take your time to read through the Zen of Python and contemplate its wisdom. But don’t take the aphorisms literally, as they’re more of a guiding set of principles rather than strict instructions. You’ll learn about their humorous origins in the next section.</p> <h2 id="how-did-the-zen-of-python-originate">How Did the Zen of Python Originate?<a class="headerlink" href="#how-did-the-zen-of-python-originate" title="Permanent link"></a></h2> <p>The idea of formulating a single document that would encapsulate Python’s fundamental philosophies emerged among the core developers in June 1999. As more and more people began coming to Python from other programming languages, they’d often bring their preconceived notions of software design that weren’t necessarily <a href="https://realpython.com/learning-paths/writing-pythonic-code/">Pythonic</a>. To help them follow the spirit of the language, a set of recommendations for writing idiomatic Python was needed.</p> <p>The initial discussion about creating such a document took place on the Python mailing list under the subject <em>The Python Way</em>. Today, you can find this conversation in the official <a href="https://mail.python.org/pipermail/python-list/1999-June/subject.html">Python-list archive</a>. If you look closely at the <a href="https://mail.python.org/pipermail/python-list/1999-June/001951.html">first message from Tim Peters</a> in that thread, then you’ll notice that he clearly outlined the Zen of Python as a joke. That original form has stuck around until this day:</p> <blockquote> <p>Clearly a job for Guido alone – although I doubt it’s one he’ll take on (fwiw, I wish he would too!). Here’s the outline he would start from, though &lt;wink&gt;:</p> <p>Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one– and preferably only one –obvious way to do it. Although that way may not be obvious at first unless you’re Dutch. Now is better than never. Although never is often better than <em>right</em> now. If the implementation is hard to explain, it’s a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea – let’s do more of those!</p> <p>There you go: 20 Pythonic Fec^H^H^HTheses on the nose, counting the one I’m leaving for Guido to fill in. If the answer to <em>any</em> Python design issue isn’t obvious after reading those – well, I just give up &lt;wink&gt;. (<a href="https://mail.python.org/pipermail/python-list/1999-June/001951.html">Source</a>)</p> </blockquote> <p>The wink and the playful way of self-censoring some <a href="https://en.wikipedia.org/wiki/Toilet_humour">toilet humor</a> are clear giveaways that Tim Peters didn’t want anyone to take his comment too seriously.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> In case you didn’t get the joke, he started to write something like <em>Feces</em> but then used <code>^H</code>—which represents a <span class="keys"><kbd class="key-backspace">Backspace</kbd></span> in older text editors like <a href="https://realpython.com/vim-and-python-a-match-made-in-heaven/">Vim</a>—to delete the last three letters and make the word <em>Theses</em>. Therefore, the intended phrase is <em>20 Pythonic Theses</em>.</p> </div> <p>Eventually, these nearly twenty theses got a proper name and were formally codified in a <a href="https://peps.python.org/pep-0001/">Python Enhancement Proposal</a> document. Each PEP document receives a number. For example, you might have stumbled on <a href="https://realpython.com/python-pep8/">PEP 8</a>, which is the style guide for writing readable Python code. Perhaps as an inside joke, the Zen of Python received the number <a href="https://peps.python.org/pep-0020/">PEP 20</a> to signify the incomplete number of aphorisms in it.</p> <p>To win your next argument about what makes good Python code, you can back up your claims with the Zen of Python. If you’d like to refer to a specific aphorism instead of the entire poem, then consider visiting <a href="https://pep20.org/">pep20.org</a>, which provides convenient clickable links to each principle.</p> <p>And, in case you want to learn the poem by heart while having some fun, you can now listen to a <a href="https://www.youtube.com/watch?v=i6G6dmVJy74">song</a> with the Zen of Python as its lyrics. <a href="https://barry.warsaw.us/">Barry Warsaw</a>, another core developer involved with Python since its early days, composed and performed this musical rendition. The song became the closing track on a special vinyl record entitled <a href="https://www.edgedb.com/blog/the-zen-side-of-the-moon"><em>The Zen Side of the Moon</em></a>, which was <a href="https://x.com/pyladies/status/1649988104433061888">auctioned</a> at <a href="https://realpython.com/python-news-april-2023/#pycon-us-2023-celebrates-its-twentieth-anniversary">PyCon US 2023</a>.</p> <p>Okay. Now that you have a rough idea of what the Zen of Python is and how it came about, you might be asking yourself whether you should really follow it.</p> <h2 id="should-you-obey-the-zen-of-python">Should You Obey the Zen of Python?<a class="headerlink" href="#should-you-obey-the-zen-of-python" title="Permanent link"></a></h2> </div><h2><a href="https://realpython.com/zen-of-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/zen-of-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: What Exactly Is the Zen of Python? https://realpython.com/quizzes/zen-of-python/ 2026-02-11T12:00:00+00:00 Learn and test the Zen of Python, its guiding aphorisms, and tips for writing clearer, more readable, and maintainable code. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/zen-of-python/">The Zen of Python</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit core aphorisms and learn how they guide readable, maintainable, and Pythonic code.</p> <p>The questions explore practical tradeoffs like breaking dense expressions into smaller parts, favoring clarity over cleverness, and making code behavior explicit.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Improving Your Tests With the Python Mock Object Library https://realpython.com/courses/improve-tests-mock-object-library/ 2026-02-10T14:00:00+00:00 Master Python testing with unittest.mock. Create mock objects to tame complex logic and unpredictable dependencies. <p>When you&rsquo;re writing robust code, <strong>tests</strong> are essential for verifying that your application logic is correct, reliable, and efficient. However, the value of your tests depends on how well they demonstrate these qualities. Obstacles such as <strong>complex logic</strong> and unpredictable <strong>dependencies</strong> can make writing valuable tests challenging. The Python mock object library, <strong><code>unittest.mock</code></strong>, can help you overcome these obstacles.</p> <p><strong>By the end of this course, you&rsquo;ll be able to:</strong></p> <ul> <li>Create Python mock objects using <code>Mock</code></li> <li>Assert that you&rsquo;re using objects as you intended</li> <li>Inspect usage data stored on your Python mocks</li> <li>Configure certain aspects of your Python mock objects</li> <li>Substitute your mocks for real objects using <code>patch()</code></li> <li>Avoid common problems inherent in Python mocking</li> </ul> <p>You&rsquo;ll begin by learning what mocking is and how it will improve your tests!</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: Python's pathlib Module: Taming the File System https://realpython.com/quizzes/python-pathlib/ 2026-02-10T12:00:00+00:00 Revisit Python's pathlib module for handling file and folder paths consistently across operating systems. Write modern, object-oriented code. <p>In this quiz, you&rsquo;ll revisit how to <a href="https://realpython.com/python-pathlib/">tame the file system with Python&rsquo;s <code>pathlib</code> module</a>.</p> <p>You&rsquo;ll reinforce core <code>pathlib</code> concepts, including checking whether a path points to a file and instantiating <code>Path</code> objects. You&rsquo;ll revisit joining paths with the <code>/</code> operator and <code>.joinpath()</code>, iterating over directory contents with <code>.iterdir()</code>, and renaming files on disk with <code>.replace()</code>.</p> <p>You&rsquo;ll also check your knowledge of common file operations such as creating empty files with <code>.touch()</code>, writing text with <code>.write_text()</code>, and extracting filename components using <code>.stem</code> and <code>.suffix</code>.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> pandas 3.0 Lands Breaking Changes and Other Python News for February 2026 https://realpython.com/python-news-february-2026/ 2026-02-09T14:00:00+00:00 Catch up on the latest Python news: pandas 3.0 breaking changes, Python 3.15 alpha JIT gains, PyTorch 2.10 deprecations, and PSF updates. <div><p>Last month brought exciting performance news for Python! The <strong>Python 3.15 alphas</strong> showed JIT compiler speed gains of up to 7–8% on some platforms, while <strong>pandas released version 3.0</strong>, delivering the most significant performance improvements in years. The Python Software Foundation also received considerable investments in Python security and launched the 2026 Python Developers Survey, and PyTorch 2.10 deprecated TorchScript.</p> <p>Time to dive into the biggest Python news 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 two Python 3.15 alpha releases in quick succession, with notable <a href="https://realpython.com/python313-free-threading-jit/">JIT compiler</a> improvements showing promising performance gains. Several <a href="/ref/glossary/pep/" class="ref-link">PEPs</a> also emerged, including one proposing a cleaner way to write multiline strings.</p> <h3 id="python-3150-alpha-4-and-5-two-releases-in-two-days">Python 3.15.0 Alpha 4 and 5: Two Releases in Two Days<a class="headerlink" href="#python-3150-alpha-4-and-5-two-releases-in-two-days" title="Permanent link"></a></h3> <p>January saw an unusual situation in Python’s release history: <a href="https://pythoninsider.blogspot.com/2026/01/python-3150-alpha-4.html">Python 3.15.0a4</a> arrived on January 13, but it was accidentally compiled against outdated source code from December 2025. The release team quickly followed up with <a href="https://www.python.org/downloads/release/python-3150a5/">3.15.0a5</a> on January 14 to correct the issue.</p> <p>Both releases continue the work on Python 3.15’s headline features:</p> <ul> <li><strong>UTF-8 as the default <a href="https://realpython.com/python-encodings-guide/">text encoding</a></strong> for files that don’t specify an encoding, via <a href="https://peps.python.org/pep-0686/">PEP 686</a></li> <li>A <strong>new statistical sampling profiler</strong> that’s high-frequency and low-overhead, via <a href="https://peps.python.org/pep-0799/">PEP 799</a></li> <li>The <strong><code>PyBytesWriter</code> C API</strong> for creating <a href="https://realpython.com/python-bytes/"><code>bytes</code> objects</a> more efficiently, via <a href="https://peps.python.org/pep-0782/">PEP 782</a></li> <li><strong>Enhanced error messages</strong> with improved clarity and usefulness</li> </ul> <p>The most exciting news for performance enthusiasts is the continued progress on Python’s experimental JIT compiler. Alpha 5 reports a <strong>4–5% performance improvement on x86-64 Linux</strong> and a <strong>7–8% speedup on AArch64 macOS</strong> compared to the standard <a href="/ref/glossary/interpreter/" class="ref-link">interpreter</a>.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> These are preview releases and are not recommended for production. The beta phase begins May 5, 2026, with the next alpha, 3.15.0a6, scheduled for February 10, 2026.</p> </div> <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> <h3 id="pep-822-drafted-dedented-multiline-strings-d-strings">PEP 822 Drafted: Dedented Multiline Strings (d-strings)<a class="headerlink" href="#pep-822-drafted-dedented-multiline-strings-d-strings" title="Permanent link"></a></h3> <p>A new <a href="/ref/glossary/pep/" class="ref-link">PEP</a> emerged in January that could make writing multiline strings clearer. <a href="https://peps.python.org/pep-0822/">PEP 822</a>, authored by Inada Naoki, proposes adding <strong>dedented multiline strings</strong> (d-strings) to Python.</p> <p>If you’ve ever written a <a href="https://realpython.com/python-strings/">multiline string</a> inside an indented function or class, you’ve likely run into the awkward choice between breaking your code’s visual structure or using <a href="https://docs.python.org/3/library/textwrap.html#textwrap.dedent"><code>textwrap.dedent()</code></a> to clean up the extra whitespace. PEP 822 offers a cleaner solution with a new <code>d</code> prefix:</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="k">def</span><span class="w"> </span><span class="nf">get_help_message</span><span class="p">():</span> <span class="c1"># Current approach</span> <span class="k">return</span> <span class="n">textwrap</span><span class="o">.</span><span class="n">dedent</span><span class="p">(</span><span class="s2">"""</span><span class="se">\</span> <span class="s2"> Usage: app [options]</span> <span class="s2"> Options:</span> <span class="s2"> -h Show this help message</span> <span class="s2"> -v Enable verbose mode</span> <span class="s2"> """</span><span class="p">)</span> <span class="c1"># Proposed d-string approach</span> <span class="k">return</span> <span class="n">d</span><span class="s2">"""</span> <span class="s2"> Usage: app [options]</span> <span class="s2"> Options:</span> <span class="s2"> -h Show this help message</span> <span class="s2"> -v Enable verbose mode</span> <span class="s2"> """</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>The <code>d</code> prefix tells Python to automatically strip the common leading whitespace from each line, using the indentation of the closing quotes as a reference. This differs slightly from <code>textwrap.dedent()</code>, which uses the least-indented line to determine how much to strip.</p> <p>The proposal targets <strong>Python 3.15</strong> and is currently in draft status. If you work with templates, <a href="https://realpython.com/python-sql-libraries/">SQL</a> queries, or any code that embeds multiline text, this feature could simplify your workflow. You can follow the discussion on the <a href="https://discuss.python.org/t/pep-822-dedented-multiline-string-d-string/105519">Python Discourse</a> and provide feedback while the PEP is still being refined.</p> <h2 id="psf-news-investments-fellows-and-survey">PSF News: Investments, Fellows, and Survey<a class="headerlink" href="#psf-news-investments-fellows-and-survey" title="Permanent link"></a></h2> <p>The <a href="/ref/glossary/psf/" class="ref-link">Python Software Foundation (PSF)</a> had a busy month with a major security investment announcement, new Fellows recognition, and the launch of the annual developers survey.</p> <h3 id="anthropic-invests-in-python-security">Anthropic Invests in Python Security<a class="headerlink" href="#anthropic-invests-in-python-security" title="Permanent link"></a></h3> </div><h2><a href="https://realpython.com/python-news-february-2026/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-news-february-2026/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #283: Improving Your GitHub Developer Experience https://realpython.com/podcasts/rpp/283/ 2026-02-06T12:00:00+00:00 What are ways to improve how you're using GitHub? How can you collaborate more effectively and improve your technical writing? This week on the show, Adam Johnson is back to talk about his new book, "Boost Your GitHub DX: Tame the Octocat and Elevate Your Productivity". <p>What are ways to improve how you're using GitHub? How can you collaborate more effectively and improve your technical writing? This week on the show, Adam Johnson is back to talk about his new book, "Boost Your GitHub DX: Tame the Octocat and Elevate Your Productivity".</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Why You Should Attend a Python Conference https://realpython.com/python-conference-guide/ 2026-02-04T14:00:00+00:00 Attending a Python conference can grow your network, skills, and confidence. Follow this guide to take your first steps toward joining a Python event. <div><p>The idea of attending a Python conference can feel intimidating. You might wonder if you know enough, if you’ll fit in, or if it’s worth your time and money. In this guide, you’ll learn about the different types of Python conferences, what they actually offer, who they’re for, and how attending one can support your learning, confidence, and connection to the wider Python community.</p> <h2 id="prerequisites">Prerequisites<a class="headerlink" href="#prerequisites" title="Permanent link"></a></h2> <p>This guide is for all Python users who want to grow their Python knowledge, get involved with the Python community, or explore new professional opportunities. Your level of experience with Python doesn’t matter, and neither does whether you use Python professionally or as a hobbyist—regularly or only from time to time. If you use Python, you’re a Python developer, and Python conferences are <em>for</em> Python developers!</p> <p><a href="https://realpython.com/podcasts/rpp/249/">Brett Cannon</a>, a <a href="/ref/glossary/cpython/" class="ref-link">CPython</a> core developer, once said:</p> <blockquote> <p>I came for the language, but I stayed for the community. (<a href="https://youtu.be/L_LLYTm-QnM?si=p-KBFHKgxqgdg357&amp;t=1006">Source</a>)</p> </blockquote> <p>If you want to experience this feeling firsthand, then this guide is for you.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your PDF:</strong> <a href="https://realpython.com/bonus/python-conference-guide-cheatsheet/" class="alert-link" data-toggle="modal" data-target="#modal-python-conference-guide-cheatsheet" markdown>Click here to download a PDF</a> with practical tips to help you feel prepared for your first Python conference.</p> </div> <h2 id="understand-what-python-conferences-actually-offer">Understand What Python Conferences Actually Offer<a class="headerlink" href="#understand-what-python-conferences-actually-offer" title="Permanent link"></a></h2> <p>Attending a Python conference offers several distinct benefits that generally fall into three categories:</p> <ul> <li> <p><strong>Personal growth</strong>: Learn new concepts, tools, and best practices through talks, tutorials, and hands-on sessions that help you deepen your Python skills and build confidence.</p> </li> <li> <p><strong>Community involvement</strong>: Meet other Python users in person, connect with open-source contributors and maintainers, and experience the collaborative culture that defines the Python community.</p> </li> <li> <p><strong>Professional opportunities</strong>: Discover potential job openings, meet companies using Python across industries, and form professional connections that can lead to future projects or roles.</p> </li> </ul> <p>The following sections explore each category in more detail to help you recognize what matters most to you when choosing a Python conference.</p> <h3 id="personal-growth">Personal Growth<a class="headerlink" href="#personal-growth" title="Permanent link"></a></h3> <p>One of the biggest benefits of attending a Python conference is the opportunity for personal growth through active learning and engagement.</p> <p>Python conferences are organized around a program of <strong>talks</strong>, <strong>tutorials</strong>, and <strong>collaborative sessions</strong> that expose you to new ideas, tools, and ways of thinking about Python. The number of program items can range from one at local meetups to over one hundred at larger conferences like <a href="https://realpython.com/pycon-guide/">PyCon US</a> and <a href="https://ep2026.europython.eu">EuroPython</a>.</p> <p>At larger events, you’re exposed to a wide breadth of topics to choose from, while at smaller events, you have fewer options but can usually attend <em>all</em> the sessions you’re interested in. <strong>Conference talks</strong> are an excellent opportunity to get exposed to new ideas, hear about new tools, or just listen to someone else talk about a topic you’re familiar with, which can be a very educational experience!</p> <p>Most of these talks are later shared on <a href="https://www.youtube.com/watch?v=iURLDirfmno">YouTube</a>, but attending in person allows you to participate in live Q&amp;A sessions where speakers answer audience questions directly. You also have the chance to meet the speaker after the talk and ask follow-up questions that wouldn’t be possible when watching a recording.</p> <p><a href="https://pycon-archive.python.org/2025/schedule/tutorials/">Tutorials</a>, on the other hand, are rarely recorded. They tend to be longer than talks and focus on <strong>hands-on coding</strong>, making them a brilliant way to gain practical, working knowledge of a Python feature or tool. Working through exercises with peers and asking questions in real time can help solidify your understanding of a topic.</p> <p>Some conferences also include <strong>collaborative</strong> <a href="https://pycon-archive.python.org/2025/events/dev-sprints/">sprint events</a>, where you get together with other attendees to contribute to open-source projects, typically with the guidance of the project maintainers themselves:</p> <figure class="js-lightbox"><a href="https://files.realpython.com/media/europython2023-sprints.e5f567c2e6f8.jpg" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block " src="https://files.realpython.com/media/europython2023-sprints.e5f567c2e6f8.jpg" width="1920" height="1280" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/europython2023-sprints.e5f567c2e6f8.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/europython2023-sprints.e5f567c2e6f8.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/europython2023-sprints.e5f567c2e6f8.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/europython2023-sprints.e5f567c2e6f8.jpg 1920w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="EuroPython 2023 attendees during sprints event" data-asset="6759"></a><figcaption class="figure-caption text-center">EuroPython Attendees Collaborating During the Sprints (Image: <a href="https://www.flickr.com/photos/europython/53132660870/in/album-72177720310704011" target="_blank">Braulio Lara</a>)</figcaption></figure> <p>Participating in sprints under the mentorship of the project maintainers is a great way to boost your confidence in your skills and get some open-source contributions under your belt. </p> <h3 id="community-involvement">Community Involvement<a class="headerlink" href="#community-involvement" title="Permanent link"></a></h3> <p>Developers are used to collaborating on open-source projects with people around the world, but working together online isn’t the same as having a face-to-face conversation. Python conferences fill that gap by giving developers a dedicated space to meet and connect in person.</p> </div><h2><a href="https://realpython.com/python-conference-guide/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/python-conference-guide/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Getting Started With Google Gemini CLI https://realpython.com/courses/getting-started-google-gemini-cli/ 2026-02-03T14:00:00+00:00 Learn how to use Gemini CLI to bring Google's AI-powered coding assistance into your terminal for faster code analysis, debugging, and fixes. <p>This video course will teach you how to use <a href="/ref/ai-coding-tools/gemini-cli/" class="ref-link">Gemini CLI</a> to bring Google&rsquo;s AI-powered coding assistance directly into your terminal. After you authenticate with your Google account, this tool will be ready to help you analyze code, identify bugs, and suggest fixes&mdash;all without leaving your familiar development environment.</p> <p>Imagine <a href="/ref/glossary/debugging/" class="ref-link">debugging</a> code without switching between your <a href="/ref/glossary/console/" class="ref-link">console</a> and browser, or picture getting instant explanations for unfamiliar projects. Like other command-line AI assistants, Google&rsquo;s Gemini CLI brings AI-powered coding assistance directly into your command line, allowing you to stay focused in your development workflow.</p> <p>Whether you&rsquo;re troubleshooting a stubborn bug, understanding legacy code, or generating documentation, this tool acts as an intelligent pair-programming partner that understands your codebase&rsquo;s context.</p> <p>You&rsquo;re about to install Gemini CLI, authenticate with Google&rsquo;s free tier, and put it to work on an actual Python project. You&rsquo;ll discover how natural language queries can help you understand code faster and catch bugs that might slip past manual review.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Terminal: First Steps and Useful Commands for Python Developers https://realpython.com/terminal-commands/ 2026-02-02T14:00:00+00:00 Learn your way around the Python terminal. You’ll practice basic commands, activate virtual environments, install packages with pip, and keep track of your code using Git. <div><p>The terminal provides Python developers with direct control over their operating system through text commands. Instead of clicking through menus, you type commands to navigate folders, run scripts, install packages, and manage version control. This command-line approach is faster and more flexible than graphical interfaces for many development tasks.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li><strong>Terminal commands</strong> like <code>cd</code>, <code>ls</code>, and <code>mkdir</code> let you navigate and organize your file system efficiently</li> <li><strong>Virtual environments</strong> isolate project dependencies, keeping your Python installations clean and manageable</li> <li><strong><code>pip</code></strong> installs, updates, and removes Python packages directly from the command line</li> <li><strong>Git commands</strong> track changes to your code and create snapshots called commits</li> <li>The <strong>command prompt</strong> displays your current directory and indicates when the terminal is ready for input</li> </ul> <p>This tutorial walks through the fundamentals of terminal usage on Windows, Linux, and macOS. The examples cover file system navigation, creating files and folders, managing packages with <code>pip</code>, and tracking code changes with Git.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Cheat Sheet:</strong> <a href="https://realpython.com/bonus/terminal-commands-cheat-sheet/" class="alert-link" data-toggle="modal" data-target="#modal-terminal-commands-cheat-sheet" markdown>Click here to download a free cheat sheet</a> of useful commands to get you started working with the terminal.</p> </div> <h2 id="install-and-open-the-terminal">Install and Open the Terminal<a class="headerlink" href="#install-and-open-the-terminal" title="Permanent link"></a></h2> <p>Back in the day, the term <em>terminal</em> referred to <a href="https://en.wikipedia.org/wiki/Computer_terminal">some clunky hardware</a> that you used to enter data into a computer. Nowadays, people are usually talking about a <a href="https://en.wikipedia.org/wiki/terminal_emulator">terminal emulator</a> when they say <strong>terminal</strong>, and they mean some kind of terminal software that you can find on most modern computers. </p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> There are two other terms that you might hear now and then in combination with the terminal:</p> <ol> <li>A <strong>shell</strong> is the program that you interact with when running commands in a terminal.</li> <li>A <strong>command-line interface (CLI)</strong> is a program designed to run in a shell inside the terminal.</li> </ol> <p>In other words, the shell provides the commands that you use in a command-line interface, and the terminal is the application that you run to access the shell.</p> </div> <p>If you’re using a Linux or macOS machine, then the terminal is already built in. You can start using it right away.</p> <p>On Windows, you also have access to command-line applications like the <a href="https://en.wikipedia.org/wiki/Cmd.exe">Command Prompt</a>. However, for this tutorial and terminal work in general, you should use the Windows terminal application instead. </p> <p>Read on to learn how to install and open the terminal on Windows and how to find the terminal on Linux and macOS.</p> <h3 id="windows">Windows<a class="headerlink" href="#windows" title="Permanent link"></a></h3> <p>The <strong>Windows terminal</strong> is a modern and feature-rich application that gives you access to the command line, multiple shells, and advanced customization options. If you have Windows 11 or above, chances are that the Windows terminal is already present on your machine. Otherwise, you can download the application from the <a href="https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701">Microsoft Store</a> or from the official <a href="https://github.com/microsoft/terminal">GitHub repository</a>.</p> <p>Before continuing with this tutorial, you need to get the terminal working on your Windows computer. You can follow the <a href="https://realpython.com/python-coding-setup-windows/">Your Python Coding Environment on Windows: Setup Guide</a> to learn <a href="https://realpython.com/python-coding-setup-windows/#installing-windows-terminal">how to install the Windows terminal</a>.</p> <p>After you install the Windows terminal, you can find it in the Start menu under <em>Terminal</em>. When you start the application, you should see a window that looks like this:</p> <figure class="js-lightbox"><a href="https://files.realpython.com/media/win-10-setup-14-windows-powershell_-_cropped.f114376b1071.png" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block " src="https://files.realpython.com/media/win-10-setup-14-windows-powershell_-_cropped.f114376b1071.png" width="1024" height="726" srcset="/cdn-cgi/image/width=256,format=auto/https://files.realpython.com/media/win-10-setup-14-windows-powershell_-_cropped.f114376b1071.png 256w, /cdn-cgi/image/width=341,format=auto/https://files.realpython.com/media/win-10-setup-14-windows-powershell_-_cropped.f114376b1071.png 341w, /cdn-cgi/image/width=512,format=auto/https://files.realpython.com/media/win-10-setup-14-windows-powershell_-_cropped.f114376b1071.png 512w, /cdn-cgi/image/width=1024,format=auto/https://files.realpython.com/media/win-10-setup-14-windows-powershell_-_cropped.f114376b1071.png 1024w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Windows Terminal with Windows PowerShell tab" data-asset="4454"></a></figure> <p>It can be handy to create a desktop shortcut for the terminal or pin the application to your task bar for easier access.</p> <h3 id="linux">Linux<a class="headerlink" href="#linux" title="Permanent link"></a></h3> <p>You can find the terminal application in the application menu of your Linux distribution. Alternatively, you can press <span class="keys"><kbd class="key-control">Ctrl</kbd><span>+</span><kbd class="key-alt">Alt</kbd><span>+</span><kbd class="key-t">T</kbd></span> on your keyboard or use the application launcher and search for the word <em>Terminal</em>.</p> <p>After opening the terminal, you should see a window similar to the screenshot below:</p> <figure class="js-lightbox"><a href="https://files.realpython.com/media/linux-terminal.28e537154512.png" target="_blank"><img loading="lazy" class="img-fluid mx-auto d-block " src="https://files.realpython.com/media/linux-terminal.28e537154512.png" width="1186" height="701" srcset="/cdn-cgi/image/width=296,format=auto/https://files.realpython.com/media/linux-terminal.28e537154512.png 296w, /cdn-cgi/image/width=395,format=auto/https://files.realpython.com/media/linux-terminal.28e537154512.png 395w, /cdn-cgi/image/width=593,format=auto/https://files.realpython.com/media/linux-terminal.28e537154512.png 593w, /cdn-cgi/image/width=1186,format=auto/https://files.realpython.com/media/linux-terminal.28e537154512.png 1186w" sizes="(min-width: 1200px) 690px, (min-width: 780px) calc(-5vw + 669px), (min-width: 580px) 510px, calc(100vw - 30px)" alt="Screenshot of the Linux terminal" data-asset="4775"></a></figure> <p>How you open the terminal may also depend on which Linux distribution you’re using. Each one has a different way of doing it. If you have trouble opening the terminal on Linux, then the Real Python community will help you out in the comments below.</p> <h3 id="macos">macOS<a class="headerlink" href="#macos" title="Permanent link"></a></h3> <p>A common way to open the terminal application on macOS is by opening the <a href="https://support.apple.com/en-us/guide/mac-help/mchlp1008/mac">Spotlight Search</a> and searching for <em>Terminal</em>. You can also find the terminal app in the application folder inside Finder.</p> <p>When you open the terminal, you see a window that looks similar to the image below:</p> </div><h2><a href="https://realpython.com/terminal-commands/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/terminal-commands/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #282: Testing Python Code for Scalability & What's New in pandas 3.0 https://realpython.com/podcasts/rpp/282/ 2026-01-30T12:00:00+00:00 How do you create automated tests to check your code for degraded performance as data sizes increase? What are the new features in pandas 3.0? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects. <p>How do you create automated tests to check your code for degraded performance as data sizes increase? What are the new features in pandas 3.0? Christopher Trudeau is back on the show this week with another batch of PyCoder's Weekly articles and projects.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> How Long Does It Take to Learn Python? https://realpython.com/how-long-does-it-take-to-learn-python/ 2026-01-28T14:00:00+00:00 This guide breaks down how long it takes to learn Python with realistic timelines, weekly study plans, and strategies to speed up your progress. <div><p>Have you read blog posts that claim you can learn Python in <em>days</em> and quickly secure a high-paying developer job? That’s an unlikely scenario and doesn’t help you prepare for a steady learning marathon. So, how long does it <em>really</em> take to learn Python, and is it worth your time investment?</p> <p><strong>By the end of this guide, you’ll understand that:</strong></p> <ul> <li>Most beginners can learn core <strong>Python fundamentals in about 2 to 6 months</strong> with consistent practice.</li> <li>You can write a tiny script in days or weeks, but real confidence comes from <strong>projects and feedback</strong>.</li> <li>Becoming <strong>job-ready</strong> often takes <strong>6 to 12 months</strong>, depending on your background and target role.</li> <li><strong>Mastery takes years</strong> because the ecosystem and specializations keep growing.</li> </ul> <p>The short answer for how long it takes to learn Python depends on your goals, time budget, and the level you’re aiming for.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get the PDF Guide:</strong> <a href="https://realpython.com/bonus/how-long-does-it-take-to-learn-python-cheatsheet/" class="alert-link" data-toggle="modal" data-target="#modal-how-long-does-it-take-to-learn-python-cheatsheet" markdown>Click here to download</a> a free PDF guide that breaks down how long it takes to learn Python and what factors affect your timeline.</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.e98ec7a26cad.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.e98ec7a26cad.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="how-long-does-it-take-to-learn-python-basics">How Long Does It Take to Learn Python Basics?<a class="headerlink" href="#how-long-does-it-take-to-learn-python-basics" title="Permanent link"></a></h2> <p>Python is beginner-friendly, and you can start writing simple programs in just a few days. But reaching the <em>basics</em> stage still takes consistent practice because you’re learning both the language itself and how to think like a programmer.</p> <p>The following timeline shows how long it typically takes to learn Python basics based on how much time you can practice each week:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Weekly practice time</th> <th>Typical timeline for basics</th> <th>What that feels like</th> </tr> </thead> <tbody> <tr> <td>2–3 hours/week</td> <td>8–12 months</td> <td>Slow but steady progress</td> </tr> <tr> <td>5–10 hours/week</td> <td>3–6 months</td> <td>Realistic pace for busy adults</td> </tr> <tr> <td>15–20 hours/week</td> <td>~2 months</td> <td>Consistent focus and fast feedback</td> </tr> <tr> <td>40+ hours/week</td> <td>~1 month</td> <td>Full-time immersion</td> </tr> </tbody> </table> </div> <p>These ranges assume about <strong>five study days per week</strong>. If you add a sixth day, you’ll likely land toward the faster end of each range.</p> <p>You’ll get better results if you use this table as a planning guide. Don’t think of it as rigid deadlines—your learning pace depends on <a href="#what-factors-influence-your-learning-speed">many factors</a>. For example, if you already know another programming language, then you can usually move faster. If you’re brand-new to coding, then expect to be at the slower end of each range.</p> <p>As a general guideline, many beginners reach the basics in about 2 to 6 months with steady practice.</p> <div class="alert alert-primary" role="alert"> <p><strong>Note:</strong> If you’re ready to fast-track your learning with an expert-guided small cohort course that gives you live guidance and accountability, then check out <a href="https://realpython.com/live/">Real Python’s live courses</a>!</p> </div> <p>With a focused schedule of around four hours per day, five days per week, you can often reach the basics stage in roughly 6 to 10 weeks, assuming you’re writing and debugging code most sessions. By then, you should be able to finish several small projects on your own.</p> <p>When you read online that someone learned Python quickly, they’re probably talking about this basics stage. And indeed, with the right mix of dedication, circumstances, and practice, learning Python basics can happen pretty fast!</p> <p>Before you go ahead and lock in a timeline, take a moment to clarify for yourself <em>why</em> you want to learn Python. Understanding your motivation for learning Python will help along the way.</p> <div class="card mb-3" id="collapse_card811377"> <div class="card-header border-0"> <p class="m-0"> <button class="btn w-100" data-toggle="collapse" data-target="#collapse811377" aria-expanded="false" aria-controls="collapse811377" markdown><span class="float-left" markdown>What Does "Learning Python" Even Mean?</span><span class="float-right text-muted">Show/Hide</span></button> </p> </div> <div class="collapse js-collapsible-section" data-parent="#collapse_card811377" id="collapse811377"> <div class="card-body"> <p>Learning Python means <em>more</em> than just learning the Python programming language. You need to know more than just the specifics of a single programming language to <strong>do something useful with your programming skills</strong>. At the same time, you don’t need to understand every single aspect of Python to be productive.</p> <p>Learning Python is about learning how to accomplish practical tasks with Python programming. It’s about having a skill set that you can use to build projects for yourself or an employer.</p> </div> </div> </div> <p>As your next step, write down your personal goal for learning Python. Always keep that goal in mind throughout your learning journey. Your goal shapes what you need to learn and how quickly you’ll progress.</p> <h2 id="whats-a-practical-30-day-learning-plan-for-complete-beginners">What’s a Practical 30-Day Learning Plan for Complete Beginners?<a class="headerlink" href="#whats-a-practical-30-day-learning-plan-for-complete-beginners" title="Permanent link"></a></h2> <p>When you’re clear about your <em>why</em>, you can start drafting your personal <a href="https://realpython.com/build-python-learning-roadmap/">Python learning roadmap</a>.</p> <p>If you’re starting from zero and can spend about 5 to 10 hours per week, the following plan keeps you moving without becoming overwhelming:</p> <ul> <li><strong>Week 1</strong>: <a href="https://realpython.com/installing-python/">Install</a> and <a href="https://realpython.com/python-coding-setup-windows/">set up</a> Python, learn about <a href="https://realpython.com/python-first-steps/">basic syntax</a>, <a href="https://realpython.com/python-variables/">variables</a>, and <a href="https://realpython.com/python-conditional-statements/">conditional statements</a></li> <li><strong>Week 2</strong>: Learn about <a href="https://realpython.com/python-data-types/">basic data types</a>, <a href="https://realpython.com/python-for-loop/"><code>for</code></a> and <a href="https://realpython.com/python-while-loop/"><code>while</code> loops</a>, and <a href="https://realpython.com/defining-your-own-python-function/">functions</a></li> <li><strong>Week 3</strong>: Work with <a href="https://realpython.com/python-list/">lists</a> and <a href="https://realpython.com/python-dicts/">dictionaries</a>, <a href="https://realpython.com/working-with-files-in-python/">file I/O</a>, and <a href="https://realpython.com/python-debug-idle/">debugging basics</a></li> <li><strong>Week 4</strong>: Build a small <a href="https://realpython.com/tutorials/projects/">project</a>, add simple <a href="https://realpython.com/python-testing/">tests</a>, and polish it through <a href="https://realpython.com/python-refactoring/">refactoring</a></li> </ul> <p>Aim to finish at least one small project by the end of the month. The project matters more than completing every tutorial or task on your checklist.</p> </div><h2><a href="https://realpython.com/how-long-does-it-take-to-learn-python/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/how-long-does-it-take-to-learn-python/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Create Callable Instances With Python's .__call__() https://realpython.com/courses/create-callable-instances-dunder-call/ 2026-01-27T14:00:00+00:00 Learn Python callables: what "callable" means, how to use dunder call, and how to build callable objects with step-by-step examples. <p>In Python, a <strong>callable</strong> is any object that you can call using a pair of parentheses and, optionally, a series of arguments. Functions, classes, and methods are all common examples of callables in Python. Besides these, you can also create custom classes that produce <strong>callable instances</strong>. To do this, you can add the <strong><code>.__call__()</code></strong> special method to your class.</p> <p>Instances of a class with a <code>.__call__()</code> method behave like functions, providing a flexible and handy way to add functionality to your objects. Understanding how to create and use callable instances is a valuable skill for any Python developer.</p> <p><strong>In this video course, you&rsquo;ll:</strong></p> <ul> <li>Understand the concept of <strong>callable objects</strong> in Python</li> <li>Create <strong>callable instances</strong> by adding a <strong><code>.__call__()</code></strong> method to your classes </li> <li>Compare <strong><code>.__init__()</code></strong> and <strong><code>.__call__()</code></strong> and understand their distinct roles</li> <li>Build practical examples that use callable instances to <strong>solve real-world problems</strong></li> </ul> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> GeoPandas Basics: Maps, Projections, and Spatial Joins https://realpython.com/geopandas/ 2026-01-26T14:00:00+00:00 Dive into GeoPandas with this tutorial covering data loading, mapping, CRS concepts, projections, and spatial joins for intuitive analysis. <div><p>GeoPandas extends pandas to make working with geospatial data in Python intuitive and powerful. If you’re looking to do geospatial tasks in Python and want a library with a pandas-like API, then GeoPandas is an excellent choice. This tutorial shows you how to accomplish four common geospatial tasks: reading in data, mapping it, applying a projection, and doing a spatial join.</p> <p><strong>By the end of this tutorial, you’ll understand that:</strong></p> <ul> <li><strong>GeoPandas extends pandas</strong> with support for spatial data. This data typically lives in a <code>geometry</code> column and allows <strong>spatial operations</strong> such as projections and spatial joins, while <strong>Folium</strong> focuses on richer interactive web maps after data preparation.</li> <li>You <strong>inspect CRS</strong> with <code>.crs</code> and <strong>reproject</strong> data using <code>.to_crs()</code> with an authority code like <code>EPSG:4326</code> or <code>ESRI:54009</code>.</li> <li>A <strong>geographic CRS</strong> stores longitude and latitude in degrees, while a <strong>projected CRS</strong> uses linear units like meters or feet for area and distance calculations.</li> <li>Spatial joins use <code>.sjoin()</code> with predicates like <code>"within"</code> or <code>"intersects"</code>, and <strong>both inputs must share the same CRS</strong> or the relationships will be computed incorrectly.</li> </ul> <p>Here’s how GeoPandas compares with alternative libraries:</p> <div class="table-responsive"> <table class="table table-hover"> <thead> <tr> <th>Use Case</th> <th>Pick pandas</th> <th>Pick Folium</th> <th>Pick GeoPandas</th> </tr> </thead> <tbody> <tr> <td>Tabular data analysis</td> <td>✅</td> <td>-</td> <td>✅</td> </tr> <tr> <td>Mapping</td> <td>-</td> <td>✅</td> <td>✅</td> </tr> <tr> <td>Projections, spatial joins</td> <td>-</td> <td>-</td> <td>✅</td> </tr> </tbody> </table> </div> <p>GeoPandas builds on pandas by adding support for geospatial data and operations like <a href="https://en.wikipedia.org/wiki/Map_projection">projections</a> and <a href="https://en.wikipedia.org/wiki/Spatial_join">spatial joins</a>. It also includes tools for creating maps. <a href="https://realpython.com/python-folium-web-maps-from-data/">Folium</a> complements this by focusing on interactive, web-based maps that you can customize more deeply.</p> <div class="alert alert-warning" role="alert"> <p><strong markdown>Get Your Code:</strong> <a href="https://realpython.com/bonus/geopandas-code/" class="alert-link" data-toggle="modal" data-target="#modal-geopandas-code" markdown>Click here to download the free sample code</a> for learning how to work with GeoPandas maps, projections, and spatial joins.</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.e98ec7a26cad.svg#@quiz"></use></svg></span> Take the Quiz:</strong></mark> Test your knowledge with our interactive “GeoPandas Basics: Maps, Projections, and Spatial Joins” 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/geopandas/" 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="GeoPandas Basics: Maps, Projections, and Spatial Joins" src="https://files.realpython.com/media/GeoPandas-for-Geospatial-Analysis-Spatial-Joins-Projections-and-Quick-Maps_Watermarked.1bd7d02f55cb.jpg" width="1920" height="1080" srcset="/cdn-cgi/image/width=480,format=auto/https://files.realpython.com/media/GeoPandas-for-Geospatial-Analysis-Spatial-Joins-Projections-and-Quick-Maps_Watermarked.1bd7d02f55cb.jpg 480w, /cdn-cgi/image/width=640,format=auto/https://files.realpython.com/media/GeoPandas-for-Geospatial-Analysis-Spatial-Joins-Projections-and-Quick-Maps_Watermarked.1bd7d02f55cb.jpg 640w, /cdn-cgi/image/width=960,format=auto/https://files.realpython.com/media/GeoPandas-for-Geospatial-Analysis-Spatial-Joins-Projections-and-Quick-Maps_Watermarked.1bd7d02f55cb.jpg 960w, /cdn-cgi/image/width=1920,format=auto/https://files.realpython.com/media/GeoPandas-for-Geospatial-Analysis-Spatial-Joins-Projections-and-Quick-Maps_Watermarked.1bd7d02f55cb.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.e98ec7a26cad.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/geopandas/" class="stretched-link"><span class="my-0 h4">GeoPandas Basics: Maps, Projections, and Spatial Joins</span></a> <p class="text-muted mb-0 small">Test GeoPandas basics for reading, mapping, projecting, and spatial joins to handle geospatial data confidently.</p> </div> </div> </div> <h2 id="getting-started-with-geopandas">Getting Started With GeoPandas<a class="headerlink" href="#getting-started-with-geopandas" title="Permanent link"></a></h2> <p>You’ll first prepare your environment and load a small dataset that you’ll use throughout the tutorial. In the next two subsections, you’ll install the necessary packages and read in a sample dataset of New York City borough boundaries. This gives you a concrete GeoDataFrame to explore as you learn the core concepts.</p> <h3 id="installing-geopandas">Installing GeoPandas<a class="headerlink" href="#installing-geopandas" title="Permanent link"></a></h3> <p>This tutorial uses two packages: <code>geopandas</code> for working with geographic data and <code>geodatasets</code> for loading sample data. It’s a good idea to install these packages inside a <a href="https://realpython.com/python-virtual-environments-a-primer/">virtual environment</a> so your project stays isolated from the rest of your system and you can manage its <a href="/ref/glossary/dependency/" class="ref-link">dependencies</a> cleanly. </p> <p>Once your virtual environment is active, you can <a href="https://realpython.com/what-is-pip/">install both packages with <code>pip</code></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.e98ec7a26cad.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><span class="s2">"geopandas[all]"</span><span class="w"> </span>geodatasets </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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p>Using the <code>[all]</code> option ensures you have everything needed for reading data, transforming coordinate systems, and creating plots. For most readers, this will work out of the box.</p> <p>If you do run into installation issues, the project’s maintainers provide alternative installation options on the <a href="https://geopandas.org/en/stable/getting_started/install.html">official installation page</a>.</p> <h3 id="reading-in-data">Reading in Data<a class="headerlink" href="#reading-in-data" title="Permanent link"></a></h3> <p>Most geospatial datasets come in <a href="https://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> or <a href="https://en.wikipedia.org/wiki/Shapefile">shapefile</a> format. The <code>read_file()</code> function can read both, and it accepts either a local file path or a URL.</p> <p>In the example below, you’ll use <code>read_file()</code> to load the New York City Borough Boundaries (NYBB) dataset. The <code>geodatasets</code> package provides a convenient path to this dataset, so you don’t need to download anything manually. You’ll also drop unnecessary columns:</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.e98ec7a26cad.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">&gt;&gt;&gt; </span><span class="kn">import</span><span class="w"> </span><span class="nn">geopandas</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">gpd</span> <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span><span class="w"> </span><span class="nn">matplotlib.pyplot</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">plt</span> <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">geodatasets</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_path</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">path_to_data</span> <span class="o">=</span> <span class="n">get_path</span><span class="p">(</span><span class="s2">"nybb"</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">nybb</span> <span class="o">=</span> <span class="n">gpd</span><span class="o">.</span><span class="n">read_file</span><span class="p">(</span><span class="n">path_to_data</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">nybb</span> <span class="o">=</span> <span class="n">nybb</span><span class="p">[[</span><span class="s2">"BoroName"</span><span class="p">,</span> <span class="s2">"Shape_Area"</span><span class="p">,</span> <span class="s2">"geometry"</span><span class="p">]]</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">nybb</span> <span class="go"> BoroName Shape_Area geometry</span> <span class="go">0 Staten Island 1.623820e+09 MULTIPOLYGON (((970217.022 145643.332, ....</span> <span class="go">1 Queens 3.045213e+09 MULTIPOLYGON (((1029606.077 156073.814, ...</span> <span class="go">2 Brooklyn 1.937479e+09 MULTIPOLYGON (((1021176.479 151374.797, ...</span> <span class="go">3 Manhattan 6.364715e+08 MULTIPOLYGON (((981219.056 188655.316, ....</span> <span class="go">4 Bronx 1.186925e+09 MULTIPOLYGON (((1012821.806 229228.265, ...</span> <span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">nybb</span><span class="p">)</span> <span class="go">&lt;class 'geopandas.geodataframe.GeoDataFrame'&gt;</span> <span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">nybb</span><span class="p">[</span><span class="s2">"geometry"</span><span class="p">])</span> <span class="go">&lt;class 'geopandas.geoseries.GeoSeries'&gt;</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.e98ec7a26cad.svg#@copy"></use></svg></span></button> </div> </code-block> <p><code>nybb</code> is a <strong>GeoDataFrame</strong>. A GeoDataFrame has rows, columns, and all the methods of a <a href="https://realpython.com/pandas-dataframe/">pandas DataFrame</a>. The difference is that it typically includes a special <code>geometry</code> column, which stores geographic shapes instead of plain numbers or text.</p> <p>The <code>geometry</code> column is a <code>GeoSeries</code>. It behaves like a normal pandas <code>Series</code>, but its values are spatial objects that you can map and run spatial queries against. In the <code>nybb</code> dataset, each borough’s geometry is a <code>MultiPolygon</code>—a shape made of several polygons—because every borough consists of multiple islands. Soon you’ll use these geometries to make maps and run spatial operations, such as finding which borough a point falls inside.</p> <h2 id="mapping-data">Mapping Data<a class="headerlink" href="#mapping-data" title="Permanent link"></a></h2> <p>Once you’ve loaded a GeoDataFrame, one of the quickest ways to understand your data is to visualize it. In this section, you’ll learn how to create both static and interactive maps. This allows you to inspect shapes, spot patterns, and confirm that your geometries look the way you expect.</p> <h3 id="creating-static-maps">Creating Static Maps<a class="headerlink" href="#creating-static-maps" title="Permanent link"></a></h3> </div><h2><a href="https://realpython.com/geopandas/?utm_source=realpython&utm_medium=rss">Read the full article at https://realpython.com/geopandas/ »</a></h2> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: GeoPandas Basics: Maps, Projections, and Spatial Joins https://realpython.com/quizzes/geopandas/ 2026-01-26T12:00:00+00:00 Test GeoPandas basics for reading, mapping, projecting, and spatial joins to handle geospatial data confidently. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/geopandas/">GeoPandas</a>.</p> <p>You&rsquo;ll review coordinate reference systems, GeoDataFrames, interactive maps, and spatial joins with <code>.sjoin()</code>. You&rsquo;ll also explore how projections affect maps and learn best practices for working with geospatial data.</p> <p>This quiz helps you confirm that you can prepare, visualize, and analyze geospatial data accurately using GeoPandas.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #281: Continuing to Improve the Learning Experience at Real Python https://realpython.com/podcasts/rpp/281/ 2026-01-23T12:00:00+00:00 If you haven't visited the Real Python website lately, then it's time to check out a great batch of updates on realpython.com! Dan Bader returns to the show this week to discuss improvements to the site and more ways to learn Python. <p>If you haven't visited the Real Python website lately, then it's time to check out a great batch of updates on realpython.com! Dan Bader returns to the show this week to discuss improvements to the site and more ways to learn Python.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: How to Integrate Local LLMs With Ollama and Python https://realpython.com/quizzes/ollama-python/ 2026-01-21T12:00:00+00:00 Check your understanding of using Ollama with Python to run local LLMs, generate text, chat, and call tools for private, offline apps. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/ollama-python/">How to Integrate Local LLMs With Ollama and Python</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit how to set up Ollama, pull models, and use chat, text generation, and tool calling from Python.</p> <p>You&rsquo;ll connect to local models through the <code>ollama</code> Python library and practice sending prompts and handling responses. You&rsquo;ll also see how local inference can improve privacy and cost efficiency while keeping your apps offline-capable.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> uv vs pip: Python Packaging and Dependency Management https://realpython.com/courses/uv-vs-pip-packaging-dependency-management/ 2026-01-20T14:00:00+00:00 Choosing between uv vs pip? This video course compares speed, reproducible environments, compatibility, and dependency management to help you pick the right tool. <p>When it comes to Python package managers, the choice often comes down to <code>uv</code> vs <code>pip</code>. You may choose <code>pip</code> for out-of-the-box availability, broad compatibility, and reliable ecosystem support. In contrast, <code>uv</code> is worth considering if you prioritize fast installs, reproducible environments, and clean uninstall behavior, or if you want to streamline workflows for new projects.</p> <p>In this video course, you&rsquo;ll compare both tools. To keep this comparison meaningful, you&rsquo;ll focus on the overlapping features, primarily <em>package installation</em> and <em>dependency management</em>.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Quiz: How to Integrate ChatGPT's API With Python Projects https://realpython.com/quizzes/chatgpt-api-python/ 2026-01-19T12:00:00+00:00 Test your knowledge of the ChatGPT API in Python. Practice sending prompts with openai and handling text and code responses in this quick quiz. <p>In this quiz, you&rsquo;ll test your understanding of <a href="https://realpython.com/chatgpt-api-python/">How to Integrate ChatGPT&rsquo;s API With Python Projects</a>.</p> <p>By working through this quiz, you&rsquo;ll revisit how to send prompts with the <code>openai</code> library, guide behavior with developer role messages, and handle text and code outputs. You&rsquo;ll also see how to integrate AI responses into your Python scripts for practical tasks.</p> <hr /> <p><em>[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #280: Considering Fast and Slow in Python Programming https://realpython.com/podcasts/rpp/280/ 2026-01-16T12:00:00+00:00 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>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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Intro to Object-Oriented Programming (OOP) in Python https://realpython.com/courses/intro-object-oriented-programming/ 2026-01-13T14:00:00+00:00 Learn 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&rsquo;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&rsquo;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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #279: Coding Python With Confidence: Beginners Live Course Participants https://realpython.com/podcasts/rpp/279/ 2026-01-09T12:00:00+00:00 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>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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Tips for Using the AI Coding Editor Cursor https://realpython.com/courses/tips-using-ai-coding-editor-cursor/ 2026-01-06T14:00:00+00:00 Learn Cursor fast: Use AI-powered coding with agents, project-aware chat, and inline edits to supercharge your VS Code workflow. <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 &amp; 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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #278: PyCoder's Weekly 2025 Top Articles & Hidden Gems https://realpython.com/podcasts/rpp/278/ 2026-01-02T12:00:00+00:00 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>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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Reading User Input From the Keyboard With Python https://realpython.com/courses/reading-user-input-from-keyboard/ 2025-12-23T14:00:00+00:00 Master 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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #277: Moving Towards Spec-Driven Development https://realpython.com/podcasts/rpp/277/ 2025-12-19T12:00:00+00:00 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>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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> Exploring Asynchronous Iterators and Iterables https://realpython.com/courses/asynchronous-iterators-iterables/ 2025-12-16T14:00:00+00:00 Learn 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&rsquo;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&rsquo;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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p> The Real Python Podcast – Episode #276: Exploring Quantum Computing & Python Frameworks https://realpython.com/podcasts/rpp/276/ 2025-12-05T12:00:00+00:00 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>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 &amp; sweet Python Trick delivered to your inbox every couple of days. <a href="https://realpython.com/python-tricks/?utm_source=realpython&amp;utm_medium=rss&amp;utm_campaign=footer">&gt;&gt; Click here to learn more and see examples</a> ]</em></p>