<?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: Kshitij Patil</title>
    <description>The latest articles on DEV Community by Kshitij Patil (@kshitij_patill).</description>
    <link>https://dev.to/kshitij_patill</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%2F4002413%2Facabcc7d-8753-497a-aeb1-06c1f18927f4.jpg</url>
      <title>DEV Community: Kshitij Patil</title>
      <link>https://dev.to/kshitij_patill</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kshitij_patill"/>
    <language>en</language>
    <item>
      <title>From Code to Output: What Really Happens When You Run Python?</title>
      <dc:creator>Kshitij Patil</dc:creator>
      <pubDate>Tue, 30 Jun 2026 10:09:34 +0000</pubDate>
      <link>https://dev.to/kshitij_patill/from-code-to-output-what-really-happens-when-you-run-python-45m6</link>
      <guid>https://dev.to/kshitij_patill/from-code-to-output-what-really-happens-when-you-run-python-45m6</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Python is an interpreted language."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You've probably heard this phrase countless times while learning Python.&lt;/p&gt;

&lt;p&gt;But let’s pause for a second…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What actually happens after you hit Run?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you execute something as simple 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;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;Hello, World!&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;How does your computer, built to understand only binary (0s and 1s), figure out what &lt;code&gt;print()&lt;/code&gt; means?&lt;/p&gt;

&lt;p&gt;The truth is, there’s a lot happening behind the scenes.&lt;/p&gt;

&lt;p&gt;Let’s break it down in a simple and intuitive way.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Hidden Workflow of Python
&lt;/h1&gt;

&lt;p&gt;Here’s a simplified overview of what happens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Source Code (.py)
          │
          ▼
Compilation Step
          │
          ▼
Bytecode (.pyc)
          │
          ▼
Python Virtual Machine (PVM)
          │
          ▼
Machine Instructions
          │
          ▼
CPU Execution
          │
          ▼
Program Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many beginners assume Python directly runs their code.&lt;/p&gt;

&lt;p&gt;But in reality, Python follows a &lt;strong&gt;two-step process&lt;/strong&gt; before execution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1, Writing Python Code
&lt;/h2&gt;

&lt;p&gt;Let’s begin with a basic script:&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="c1"&gt;# hello.py
&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;Hello, World!&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;At this stage, your file is just plain text.&lt;/p&gt;

&lt;p&gt;Your computer doesn’t understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions like &lt;code&gt;print()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Control structures like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Variables or expressions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It only understands low-level machine instructions.&lt;/p&gt;

&lt;p&gt;So Python needs to translate your code first.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2, The Python Interpreter Steps In
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you’re invoking the &lt;strong&gt;Python Interpreter&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The most widely used implementation is &lt;strong&gt;CPython&lt;/strong&gt;, written in C.&lt;/p&gt;

&lt;p&gt;Its responsibilities include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reading your code&lt;/li&gt;
&lt;li&gt;Checking for syntax errors&lt;/li&gt;
&lt;li&gt;Converting it into bytecode&lt;/li&gt;
&lt;li&gt;Executing that bytecode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So Python doesn’t directly interpret your source code, it first compiles it into an intermediate form.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3, Bytecode: Python’s Internal Language
&lt;/h2&gt;

&lt;p&gt;Instead of converting your code straight into machine instructions, Python transforms it into &lt;strong&gt;bytecode&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of bytecode as a simplified, platform-independent instruction set.&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;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;y&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="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;might internally look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOAD_CONST 5
STORE_NAME x

LOAD_CONST 10
STORE_NAME y

LOAD_NAME x
LOAD_NAME y

BINARY_ADD

PRINT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don’t need to memorize this, it just shows how Python simplifies your code before execution.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Are &lt;code&gt;.pyc&lt;/code&gt; Files?
&lt;/h1&gt;

&lt;p&gt;You might have seen a folder 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;__pycache__
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside it, files like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hello.cpython-313.pyc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These &lt;code&gt;.pyc&lt;/code&gt; files store compiled bytecode.&lt;/p&gt;

&lt;p&gt;Python uses them to avoid recompiling unchanged files, making your programs start faster.&lt;/p&gt;




&lt;h1&gt;
  
  
  Curious? Inspect Bytecode Yourself
&lt;/h1&gt;

&lt;p&gt;Python provides a module called &lt;code&gt;dis&lt;/code&gt; to view bytecode.&lt;/p&gt;

&lt;p&gt;Try 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="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dis&lt;/span&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="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;span class="n"&gt;dis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOAD_FAST 0 (a)
LOAD_FAST 1 (b)
BINARY_ADD
RETURN_VALUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is exactly what Python executes internally.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 4, The Python Virtual Machine (PVM)
&lt;/h1&gt;

&lt;p&gt;Now comes execution.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Python Virtual Machine (PVM)&lt;/strong&gt; is the engine that runs bytecode.&lt;/p&gt;

&lt;p&gt;It’s not hardware, it’s part of the interpreter.&lt;/p&gt;

&lt;p&gt;It works in a loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fetch → Decode → Execute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Fetch the next instruction&lt;/li&gt;
&lt;li&gt;Decode what it means&lt;/li&gt;
&lt;li&gt;Execute it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This cycle continues until your program finishes.&lt;/p&gt;




&lt;h1&gt;
  
  
  Walking Through Execution
&lt;/h1&gt;

&lt;p&gt;Let’s revisit:&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;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;Hello, World!&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;Here’s what happens step by step:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. You run the script
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python hello.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;↓&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Python reads your code
&lt;/h3&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;h3&gt;
  
  
  3. It compiles it into bytecode
&lt;/h3&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;h3&gt;
  
  
  4. The PVM executes instructions like:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOAD_CONST "Hello, World!"
CALL_FUNCTION print
RETURN_VALUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;↓&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Output appears
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done!&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Isn’t Python as Fast as C?
&lt;/h1&gt;

&lt;p&gt;Let’s compare:&lt;/p&gt;

&lt;h3&gt;
  
  
  C Execution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C Code → Compiler → Machine Code → CPU
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Python Execution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Code → Bytecode → PVM → CPU
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python adds an extra layer (the PVM), which introduces overhead.&lt;/p&gt;

&lt;p&gt;That’s why Python is generally slower for heavy computations.&lt;/p&gt;

&lt;p&gt;But this design also makes Python:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Portable&lt;/li&gt;
&lt;li&gt;Easy to use&lt;/li&gt;
&lt;li&gt;Flexible&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Memory Management in Python
&lt;/h1&gt;

&lt;p&gt;Python handles memory automatically.&lt;/p&gt;

&lt;p&gt;It stores objects in a region called the &lt;strong&gt;heap&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When objects are no longer needed, Python cleans them up using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reference counting&lt;/li&gt;
&lt;li&gt;Garbage collection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means you don’t have to manually manage memory like in C or C++.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple Way to Think About It
&lt;/h1&gt;

&lt;p&gt;Imagine you're speaking to someone who doesn’t understand your language.&lt;/p&gt;

&lt;p&gt;You use a translator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You → Translator → Listener
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Python terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You&lt;/strong&gt; → Programmer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python Code&lt;/strong&gt; → Your language&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PVM&lt;/strong&gt; → Translator&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPU&lt;/strong&gt; → Listener&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The CPU never understands Python directly, the PVM bridges that gap.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Once you understand what happens behind the scenes, Python feels less like magic and more like a well-designed system.&lt;/p&gt;

&lt;p&gt;So next time someone says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Python is an interpreted language."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You’ll know the full story.&lt;/p&gt;

&lt;p&gt;Python first compiles your code into &lt;strong&gt;bytecode&lt;/strong&gt;, then executes it using the &lt;strong&gt;Python Virtual Machine&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And that journey, from a simple &lt;code&gt;.py&lt;/code&gt; file to actual output, is what makes Python both powerful and accessible.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thanks for reading!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I’m sharing my learning journey in Python, backend development, and software engineering. If you found this helpful, feel free to follow along for more simple explanations of complex topics.&lt;/p&gt;

</description>
      <category>python</category>
      <category>internals</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
