<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ibrahim Popatiya on Medium]]></title>
        <description><![CDATA[Stories by Ibrahim Popatiya on Medium]]></description>
        <link>https://medium.com/@ibrahim.popatiya3?source=rss-95fee98c3911------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_EqNdKbNoLcW9nYq</url>
            <title>Stories by Ibrahim Popatiya on Medium</title>
            <link>https://medium.com/@ibrahim.popatiya3?source=rss-95fee98c3911------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:07:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ibrahim.popatiya3/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Python Loop Concepts Every Interviewer Expects You to Know (part 2)]]></title>
            <link>https://medium.com/@ibrahim.popatiya3/the-python-loop-concepts-every-interviewer-expects-you-to-know-part-2-bdf46e2c7c78?source=rss-95fee98c3911------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdf46e2c7c78</guid>
            <category><![CDATA[loop]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Ibrahim Popatiya]]></dc:creator>
            <pubDate>Sun, 12 Jul 2026 09:59:21 GMT</pubDate>
            <atom:updated>2026-07-12T09:59:21.504Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Loops Explained (Part 2): Advanced Loops, Comprehensions &amp; Interview Concepts</h3><p>Welcome back to our <strong>Python Mastery Playlist</strong>! This is the <strong>fourth article</strong> in the series. In <strong>Part 1 of Loops</strong>, we explored for loops, while loops, range(), loop control statements, nested loops, enumerate(), and zip(). If you haven&#39;t read that article yet, I highly recommend starting there before diving into these advanced concepts.</p><p>Today, we’ll move beyond simply writing loops and understand <strong>how they work behind the scenes</strong>. We’ll also explore Pythonic techniques that make your code cleaner, faster, and more efficient — topics that are frequently discussed in technical interviews.</p><h3>Why Learn Advanced Loops?</h3><p>Most beginners know <strong>how</strong> to write a loop.</p><p>Experienced Python developers know:</p><ul><li>Why one approach is better than another.</li><li>How Python executes loops internally.</li><li>How to write cleaner and faster code.</li><li>How to optimize memory usage.</li></ul><p>That’s exactly what we’ll learn today.</p><h3>Iterable vs Iterator</h3><p>These two terms sound similar, but they are completely different.</p><p>Understanding this difference is one of the most common Python interview questions.</p><h3>What is an Iterable?</h3><p>An <strong>iterable</strong> is any object that can be looped over.</p><p>Examples include:</p><ul><li>Lists</li><li>Tuples</li><li>Sets</li><li>Dictionaries</li><li>Strings</li><li>range()</li></ul><p>Example:</p><pre>numbers = [10, 20, 30]</pre><pre>for num in numbers:<br>    print(num)</pre><p>Since a list can be iterated over, it is an iterable.</p><h3>What is an Iterator?</h3><p>An <strong>iterator</strong> is an object that returns one element at a time.</p><p>Instead of giving all values together, it provides the next value whenever requested.</p><p>Create an iterator using iter().</p><pre>numbers = [10, 20, 30]</pre><pre>it = iter(numbers)</pre><pre>print(next(it))<br>print(next(it))<br>print(next(it))</pre><p>Output</p><pre>10<br>20<br>30</pre><p>Each call to next() moves the iterator forward.</p><h3>What Happens When There Are No More Values?</h3><p>Let’s continue.</p><pre>print(next(it))</pre><p>Python raises:</p><pre>StopIteration</pre><p>This exception tells Python that the iterator has been exhausted.</p><h3>How Does a for Loop Work Internally?</h3><p>When we write:</p><pre>for number in numbers:<br>    print(number)</pre><p>Python roughly performs something like this behind the scenes.</p><pre>it = iter(numbers)</pre><pre>while True:<br>    try:<br>        number = next(it)<br>        print(number)</pre><pre>    except StopIteration:<br>        break</pre><p>This is why every iterable must provide an iterator.</p><p>Understanding this internal mechanism is a favorite question in senior Python interviews.</p><h3>Writing Pythonic Loops</h3><p>Suppose you have a list.</p><pre>numbers = [10, 20, 30]</pre><p>Many beginners write:</p><pre>for i in range(len(numbers)):<br>    print(numbers[i])</pre><p>While it works, it isn’t the most Pythonic solution.</p><p>A cleaner approach is:</p><pre>for number in numbers:<br>    print(number)</pre><p>It is shorter, easier to read, and often preferred in professional codebases.</p><h3>List Comprehension</h3><p>Suppose we want the squares of numbers from 0 to 4.</p><p>Traditional approach:</p><pre>squares = []</pre><pre>for i in range(5):<br>    squares.append(i * i)</pre><pre>print(squares)</pre><p>Output</p><pre>[0, 1, 4, 9, 16]</pre><p>Python provides a much cleaner solution.</p><pre>squares = [i * i for i in range(5)]</pre><pre>print(squares)</pre><p>Output</p><pre>[0, 1, 4, 9, 16]</pre><p>This is called <strong>List Comprehension</strong>.</p><p>It combines looping and list creation into a single line.</p><h3>Why Use List Comprehensions?</h3><p>They are:</p><ul><li>More readable</li><li>More concise</li><li>Usually faster than traditional loops</li><li>Widely used in professional Python projects</li></ul><p>If you read open-source Python code, you’ll see comprehensions everywhere.</p><h3>Conditional List Comprehension</h3><p>Suppose we only want even numbers.</p><p>Traditional way:</p><pre>evens = []</pre><pre>for i in range(10):<br>    if i % 2 == 0:<br>        evens.append(i)</pre><pre>print(evens)</pre><p>Pythonic way:</p><pre>evens = [x for x in range(10) if x % 2 == 0]</pre><pre>print(evens)</pre><p>Output</p><pre>[0, 2, 4, 6, 8]</pre><p>Much cleaner.</p><h3>Dictionary Comprehension</h3><p>Comprehensions are not limited to lists.</p><p>Create a dictionary of squares.</p><pre>squares = {x: x * x for x in range(5)}</pre><pre>print(squares)</pre><p>Output</p><pre>{<br>    0: 0,<br>    1: 1,<br>    2: 4,<br>    3: 9,<br>    4: 16<br>}</pre><h3>Set Comprehension</h3><p>Similarly,</p><pre>numbers = {x * x for x in range(5)}</pre><pre>print(numbers)</pre><p>Output</p><pre>{0, 1, 4, 9, 16}</pre><h3>Generator Expressions</h3><p>Imagine generating one million squared numbers.</p><p>Using a list:</p><pre>numbers = [x * x for x in range(1000000)]</pre><p>Python creates every value immediately and stores them in memory.</p><p>Now consider this.</p><pre>numbers = (x * x for x in range(1000000))</pre><p>Notice the parentheses.</p><p>This creates a <strong>generator expression</strong>.</p><p>Instead of storing every value, Python generates numbers <strong>only when needed</strong>.</p><p>This approach is far more memory efficient.</p><h3>Why Are Generators Useful?</h3><p>Generators are commonly used when:</p><ul><li>Reading huge files</li><li>Processing large datasets</li><li>Streaming data</li><li>Building scalable applications</li></ul><p>Instead of consuming large amounts of memory, they generate values lazily.</p><h3>Time Complexity of Loops</h3><p>Understanding complexity is important for coding interviews.</p><h3>Single Loop</h3><pre>for i in range(n):<br>    print(i)</pre><p>Time Complexity:</p><pre>O(n)</pre><p>The loop runs <strong>n</strong> times.</p><h3>Nested Loop</h3><pre>for i in range(n):<br>    for j in range(n):<br>        print(i, j)</pre><p>Time Complexity:</p><pre>O(n²)</pre><p>The inner loop executes for every iteration of the outer loop.</p><p>Nested loops are common in DSA problems involving matrices and grids.</p><h3>Common Interview Questions</h3><h3>What is the difference between an Iterable and an Iterator?</h3><p><strong>Iterable</strong></p><ul><li>Can be looped over.</li><li>Examples: list, tuple, dictionary, string, set.</li></ul><p><strong>Iterator</strong></p><ul><li>Produces one value at a time.</li><li>Supports the next() function.</li></ul><h3>How does a for loop work internally?</h3><p>A for loop internally uses:</p><ul><li>iter()</li><li>next()</li><li>StopIteration</li></ul><h3>What is the difference between range() and list(range())?</h3><pre>range(1000000)</pre><p>Creates a lightweight range object.</p><pre>list(range(1000000))</pre><p>Creates one million integers in memory.</p><p>range() is much more memory efficient.</p><h3>What is List Comprehension?</h3><p>A compact syntax for creating lists using loops.</p><p>Example:</p><pre>[x * x for x in range(5)]</pre><h3>Why use Generator Expressions?</h3><p>Because they generate values lazily and consume much less memory.</p><h3>Which is faster: traditional loops or comprehensions?</h3><p>In most situations, comprehensions are slightly faster and significantly more readable.</p><h3>One-Minute Revision</h3><p>✅ Iterable → Anything you can loop over.</p><p>✅ Iterator → Returns one value at a time using next().</p><p>✅ iter() creates an iterator.</p><p>✅ next() retrieves the next element.</p><p>✅ When iteration ends, Python raises StopIteration.</p><p>✅ A for loop internally uses iter() and next().</p><p>✅ List Comprehensions provide a cleaner way to create lists.</p><p>✅ Dictionary and Set Comprehensions work similarly.</p><p>✅ Generator Expressions are memory efficient.</p><p>✅ Single Loop → <strong>O(n)</strong></p><p>✅ Nested Loop → <strong>O(n²)</strong></p><h3>Final Thoughts</h3><p>Congratulations! 🎉</p><p>You’ve now completed one of the most important Python topics.</p><p>Across both articles, you’ve learned everything from basic for and while loops to advanced concepts like iterators, comprehensions, generators, and the internal working of Python&#39;s iteration system.</p><p>These aren’t just concepts for writing better code — they’re the same ideas that appear repeatedly in Python interviews, coding assessments, and real-world software development.</p><p>The best way to master loops isn’t by memorizing them — it’s by building projects, solving problems, and experimenting with different approaches.</p><p>In the next article of our <strong>Python Mastery Playlist</strong>, we’ll explore another essential Python concept and continue strengthening our programming foundation.</p><p>Until then…</p><p><strong>Keep learning. Keep building. And keep coding.</strong> 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdf46e2c7c78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Loops Explained (Part 1): Stop Repeating Yourself and Let Python Do the Work!]]></title>
            <link>https://medium.com/@ibrahim.popatiya3/python-loops-explained-part-1-stop-repeating-yourself-and-let-python-do-the-work-71e509400d4f?source=rss-95fee98c3911------2</link>
            <guid isPermaLink="false">https://medium.com/p/71e509400d4f</guid>
            <category><![CDATA[loop]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[loops-in-python]]></category>
            <dc:creator><![CDATA[Ibrahim Popatiya]]></dc:creator>
            <pubDate>Thu, 09 Jul 2026 07:34:13 GMT</pubDate>
            <atom:updated>2026-07-09T07:34:13.897Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back to our <strong>Python Mastery Playlist</strong>! 🚀 This is the <strong>third article</strong> in the series, where we’re learning Python one concept at a time. In the previous article, we explored <strong>Functions</strong> and learned how to write reusable blocks of code. If you haven’t read it yet, I recommend checking it out first because functions and loops are often used together in real-world programs.</p><p>Today, we’re diving into another fundamental concept in Python — <strong>Loops</strong>. By the end of this article, you’ll know how to automate repetitive tasks, iterate over different data types, and understand some of the most frequently asked loop questions in Python interviews.</p><h3>Imagine Doing This…</h3><p>Suppose your manager asks you to print:</p><blockquote><em>“Welcome to Python”</em></blockquote><p>write 100 times.</p><p>Would you write this?</p><pre>print(&quot;Welcome to Python&quot;)<br>print(&quot;Welcome to Python&quot;)<br>print(&quot;Welcome to Python&quot;)<br>...</pre><p>Of course not.</p><p>That’s where <strong>loops</strong> come in.</p><p>A loop lets Python repeat a block of code automatically, saving time, reducing mistakes, and making your programs much cleaner.</p><h3>What is a Loop?</h3><p>A <strong>loop</strong> is a programming construct that repeatedly executes a block of code until a condition is met or an iterable is exhausted.</p><p>Instead of writing the same code multiple times, you write it once.</p><p>Without a loop:</p><pre>print(&quot;Hello&quot;)<br>print(&quot;Hello&quot;)<br>print(&quot;Hello&quot;)</pre><p>Using a loop:</p><pre>for i in range(3):<br>    print(&quot;Hello&quot;)</pre><p><strong>Output</strong></p><pre>Hello<br>Hello<br>Hello</pre><p>Simple, cleaner, and scalable.</p><h3>Why Do We Need Loops?</h3><p>Imagine printing numbers from <strong>1 to 1,000,000</strong>.</p><p>Without loops?</p><p>Impossible.</p><p>With loops?</p><pre>for number in range(1, 1000001):<br>    print(number)</pre><p>Loops are everywhere in programming.</p><p>They help us:</p><ul><li>Process lists</li><li>Read files</li><li>Analyze data</li><li>Build games</li><li>Handle user input</li><li>Solve algorithms</li><li>Automate repetitive tasks</li></ul><p>If you’ve ever used Instagram, Netflix, or YouTube, you’ve already experienced loops. Every time these apps display lists of posts, videos, or comments, loops are working behind the scenes.</p><h3>Types of Loops in Python</h3><p>Python mainly provides two types of loops.</p><h3>1. for Loop</h3><p>Used when you already know what you want to iterate over.</p><h3>2. while Loop</h3><p>Used when repetition depends on a condition.</p><p>Let’s understand both.</p><h3>The for Loop</h3><p>A <strong>for loop</strong> iterates over an iterable like a list, string, tuple, dictionary, or range.</p><p>Syntax:</p><pre>for variable in iterable:<br>    # code</pre><p>Example:</p><pre>for i in range(5):<br>    print(i)</pre><p>Output</p><pre>0<br>1<br>2<br>3<br>4</pre><p>Notice that Python automatically updates the value of i during each iteration.</p><h3>Understanding range()</h3><p>You’ll use range() in almost every Python program.</p><p>General syntax:</p><pre>range(start, stop, step)</pre><p>Let’s see how it works.</p><h3>Example 1</h3><pre>range(5)</pre><p>Produces</p><pre>0 1 2 3 4</pre><h3>Example 2</h3><pre>for i in range(1, 6):<br>    print(i)</pre><p>Output</p><pre>1<br>2<br>3<br>4<br>5</pre><p>Notice that the <strong>stop value is excluded</strong>.</p><h3>Example 3</h3><p>Skip numbers using the step value.</p><pre>for i in range(0, 10, 2):<br>    print(i)</pre><p>Output</p><pre>0<br>2<br>4<br>6<br>8</pre><h3>Counting Backwards (Negative Step)</h3><p>Many interviewers ask this.</p><pre>for i in range(5, 0, -1):<br>    print(i)</pre><p>Output</p><pre>5<br>4<br>3<br>2<br>1</pre><p>A negative step lets you iterate in reverse order.</p><h3>Looping Through Strings</h3><p>Strings are iterable.</p><pre>name = &quot;Python&quot;</pre><pre>for letter in name:<br>    print(letter)</pre><p>Output</p><pre>P<br>y<br>t<br>h<br>o<br>n</pre><p>Python gives one character at a time.</p><h3>Looping Through Lists</h3><p>Lists are one of the most common iterables.</p><pre>numbers = [10, 20, 30]</pre><pre>for number in numbers:<br>    print(number)</pre><p>Output</p><pre>10<br>20<br>30</pre><h3>Looping Through Tuples</h3><p>Tuples work exactly like lists.</p><pre>data = (1, 2, 3)</pre><pre>for item in data:<br>    print(item)</pre><p>Output</p><pre>1<br>2<br>3</pre><h3>Looping Through Sets</h3><p>Sets are also iterable.</p><pre>numbers = {10, 20, 30}</pre><pre>for number in numbers:<br>    print(number)</pre><p>One important thing to remember:</p><p>⚠️ Sets are <strong>unordered</strong>, so the output order is not guaranteed.</p><p>This is a common interview question.</p><h3>Looping Through Dictionaries</h3><p>Dictionaries are slightly different.</p><h3>Loop Through Keys</h3><pre>student = {<br>    &quot;name&quot;: &quot;Faizan&quot;,<br>    &quot;age&quot;: 22<br>}</pre><pre>for key in student:<br>    print(key)</pre><p>Output</p><pre>name<br>age</pre><h3>Loop Through Values</h3><pre>for value in student.values():<br>    print(value)</pre><p>Output</p><pre>Faizan<br>22</pre><h3>Loop Through Both Keys and Values</h3><pre>for key, value in student.items():<br>    print(key, value)</pre><p>Output</p><pre>name Faizan<br>age 22</pre><p>This is the preferred and most Pythonic approach.</p><h3>The while Loop</h3><p>Unlike a for loop, a while loop keeps running <strong>as long as a condition remains True</strong>.</p><p>Syntax</p><pre>while condition:<br>    # code</pre><p>Example</p><pre>count = 1</pre><pre>while count &lt;= 5:<br>    print(count)<br>    count += 1</pre><p>Output</p><pre>1<br>2<br>3<br>4<br>5</pre><p>Notice how we manually update the variable.</p><p>If we forget to increment it, the loop never ends.</p><h3>Infinite Loops</h3><p>Consider this example.</p><pre>while True:<br>    print(&quot;Running...&quot;)</pre><p>This loop never stops.</p><p>Infinite loops are actually useful in:</p><ul><li>Game engines</li><li>Chat applications</li><li>Servers</li><li>Event-driven programs</li></ul><p>They usually rely on a condition inside the loop to exit safely.</p><h3>The break Statement</h3><p>Sometimes we want to stop a loop immediately.</p><pre>for number in range(10):</pre><pre>    if number == 5:<br>        break</pre><pre>    print(number)</pre><p>Output</p><pre>0<br>1<br>2<br>3<br>4</pre><p>Once Python reaches break, the loop ends immediately.</p><h3>The continue Statement</h3><p>Instead of stopping the loop, we may only want to skip one iteration.</p><pre>for number in range(5):</pre><pre>    if number == 2:<br>        continue</pre><pre>    print(number)</pre><p>Output</p><pre>0<br>1<br>3<br>4</pre><p>The value 2 is skipped.</p><h3>The pass Statement</h3><p>Sometimes Python expects a block of code, but you’re not ready to write it.</p><pre>for number in range(5):<br>    pass</pre><p>pass does absolutely nothing.</p><p>It simply acts as a placeholder.</p><h3>Python’s Hidden Feature: else with Loops</h3><p>Many Python developers don’t even know this feature exists.</p><pre>for number in range(3):<br>    print(number)</pre><pre>else:<br>    print(&quot;Loop Completed&quot;)</pre><p>Output</p><pre>0<br>1<br>2<br>Loop Completed</pre><p>Now consider this.</p><pre>for number in range(5):</pre><pre>    if number == 2:<br>        break</pre><pre>else:<br>    print(&quot;Loop Completed&quot;)</pre><p>Nothing is printed after the loop.</p><p>Why?</p><p>Because the else block only executes if the loop finishes <strong>normally</strong>.</p><p>If break is executed, the else block is skipped.</p><p>This is a favorite Python interview question.</p><h3>Nested Loops</h3><p>A loop inside another loop is called a nested loop.</p><pre>for i in range(3):</pre><pre>    for j in range(2):<br>        print(i, j)</pre><p>Output</p><pre>0 0<br>0 1<br>1 0<br>1 1<br>2 0<br>2 1</pre><p>Nested loops are commonly used in matrix operations, grids, games, and pattern-based interview questions.</p><h3>Printing Patterns</h3><p>One of the most popular beginner interview questions.</p><pre>for i in range(3):</pre><pre>    for j in range(3):<br>        print(&quot;*&quot;, end=&quot;&quot;)</pre><pre>    print()</pre><p>Output</p><pre>***<br>***<br>***</pre><p>The inner loop prints stars.</p><p>The outer loop moves to the next line.</p><h3>Using enumerate()</h3><p>Suppose you have a list.</p><pre>fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Mango&quot;]</pre><p>Without enumerate():</p><pre>for i in range(len(fruits)):<br>    print(i, fruits[i])</pre><p>A cleaner solution:</p><pre>for index, fruit in enumerate(fruits):<br>    print(index, fruit)</pre><p>Output</p><pre>0 Apple<br>1 Banana<br>2 Mango</pre><p>This is the recommended Pythonic approach.</p><h3>Looping Through Multiple Lists with zip()</h3><p>Imagine you have two related lists.</p><pre>names = [&quot;Alice&quot;, &quot;Bob&quot;]<br>ages = [21, 22]</pre><p>Instead of using indexes:</p><pre>for name, age in zip(names, ages):<br>    print(name, age)</pre><p>Output</p><pre>Alice 21<br>Bob 22</pre><p>zip() combines multiple iterables and lets you iterate over them together.</p><h3>Reverse Looping</h3><p>Python also provides an elegant way to iterate backwards.</p><pre>for number in reversed(range(5)):<br>    print(number)</pre><p>Output</p><pre>4<br>3<br>2<br>1<br>0</pre><p>Much cleaner than manually writing a negative step.</p><h3>Common Interview Questions</h3><h3>What is the difference between for and while?</h3><ul><li>for loops iterate over an iterable.</li><li>while loops continue until a condition becomes False.</li></ul><h3>What is the difference between break and continue?</h3><ul><li>break exits the loop completely.</li><li>continue skips only the current iteration.</li></ul><h3>What does pass do?</h3><p>Nothing.</p><p>It’s simply a placeholder.</p><h3>When does the else block execute?</h3><p>Only when the loop finishes without encountering a break.</p><h3>Why use enumerate()?</h3><p>Because it provides both the index and the value together, making your code cleaner and easier to read.</p><h3>What does zip() do?</h3><p>It combines multiple iterables and lets you iterate over them simultaneously.</p><h3>Quick Revision</h3><p>✅ Loops help automate repetitive tasks.</p><p>✅ Python has two main loops: for and while.</p><p>✅ range(start, stop, step) generates sequences of numbers.</p><p>✅ Strings, lists, tuples, sets, and dictionaries are all iterable.</p><p>✅ break exits a loop immediately.</p><p>✅ continue skips the current iteration.</p><p>✅ pass acts as a placeholder.</p><p>✅ else executes only when the loop ends normally.</p><p>✅ Nested loops are useful for patterns and matrices.</p><p>✅ enumerate() returns both index and value.</p><p>✅ zip() lets you loop through multiple iterables together.</p><h3>What’s Next?</h3><p>So far, you’ve learned how to repeat code efficiently, iterate over different data structures, and control the flow of loops like a Python developer.</p><p>But there’s still another side of loops that every serious Python programmer should know.</p><p>In the next article, we’ll explore <strong>Advanced Python Loops</strong>, where you’ll learn about <strong>Iterables vs Iterators</strong>, how a for loop works internally using iter() and next(), <strong>List Comprehensions</strong>, <strong>Generator Expressions</strong>, <strong>Time Complexity</strong>, and the interview-level concepts that companies like Google, Microsoft, and Meta often expect.</p><p>See you in the next loop! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71e509400d4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Functions Explained: Write Once, Use Forever ]]></title>
            <link>https://medium.com/@ibrahim.popatiya3/python-functions-explained-write-once-use-forever-9b610213ab37?source=rss-95fee98c3911------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b610213ab37</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Ibrahim Popatiya]]></dc:creator>
            <pubDate>Wed, 08 Jul 2026 11:19:11 GMT</pubDate>
            <atom:updated>2026-07-08T11:19:11.397Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back to our <strong>Python Mastery Playlist</strong>! 🚀 This is the <strong>second article</strong> in the series, where we’re building a strong Python foundation one concept at a time. In the previous blog, we explored <strong>Variables.</strong></p><p>Imagine you’re building a calculator.</p><p>You need to add two numbers in one place, calculate a bill somewhere else, and find a student’s average later.</p><p>Would you write the same addition logic again and again?</p><p>Probably not.</p><p>That’s exactly why <strong>functions</strong> exist.</p><p>Functions are one of the most important concepts in Python. They make your code reusable, organized, easier to understand, and much easier to maintain. Whether you’re preparing for coding interviews, learning automation, web development, or data science, mastering functions is essential.</p><p>In this article, we’ll cover everything from the basics to interview-level concepts with practical examples.</p><h3>What is a Function?</h3><p>A <strong>function</strong> is a reusable block of code designed to perform a specific task.</p><p>Instead of rewriting the same code repeatedly, you define it once and call it whenever needed.</p><pre>def greet():<br>    print(&quot;Hello&quot;)</pre><pre>greet()</pre><p><strong>Output</strong></p><pre>Hello</pre><p>Think of a function like a coffee machine.</p><p>You press a button, and it performs a predefined task every single time without needing you to explain the process again.</p><h3>Why Do We Need Functions?</h3><p>Let’s print the same message three times.</p><h3>Without Functions</h3><pre>print(&quot;Welcome&quot;)<br>print(&quot;Welcome&quot;)<br>print(&quot;Welcome&quot;)</pre><p>Now imagine needing this message in 100 different places.</p><h3>With Functions</h3><pre>def welcome():<br>    print(&quot;Welcome&quot;)</pre><pre>welcome()<br>welcome()<br>welcome()</pre><p>Much cleaner.</p><h3>Benefits of Functions</h3><ul><li>Write code once and reuse it anywhere.</li><li>Improve readability.</li><li>Simplify debugging.</li><li>Make maintenance easier.</li><li>Break large programs into smaller modules.</li><li>Encourage clean, organized programming.</li></ul><h3>Function Syntax</h3><p>Every function follows a simple structure.</p><pre>def function_name():<br>    # Function body</pre><p>Example:</p><pre>def greet():<br>    print(&quot;Hello&quot;)</pre><p>Calling the function:</p><pre>greet()</pre><p>A function won’t execute automatically. It only runs when you call it.</p><h3>Understanding Function Components</h3><p>Consider this function:</p><pre>def add(a, b):<br>    return a + b</pre><p>Let’s break it down.</p><ul><li>def → Keyword used to define a function.</li><li>add → Function name.</li><li>a, b → Parameters.</li><li>return → Sends the result back to the caller.</li></ul><p>Each part has a specific purpose.</p><h3>Parameters vs Arguments</h3><p>This is one of the most common interview questions.</p><h3>Parameters</h3><p>Parameters are variables declared in the function definition.</p><pre>def greet(name):<br>    print(name)</pre><p>Here, name is a <strong>parameter</strong>.</p><h3>Arguments</h3><p>Arguments are the actual values passed to the function.</p><pre>greet(&quot;Faizan&quot;)</pre><p>Here, &quot;Faizan&quot; is an <strong>argument</strong>.</p><p><strong>Quick Trick</strong></p><ul><li>Parameter → Placeholder</li><li>Argument → Actual Value</li></ul><h3>The Return Statement</h3><p>A function can return a value.</p><pre>def add(a, b):<br>    return a + b</pre><pre>result = add(2, 3)</pre><pre>print(result)</pre><p><strong>Output</strong></p><pre>5</pre><p>The returned value can be stored, reused, or passed to another function.</p><h3>What Happens Without return?</h3><pre>def add(a, b):<br>    a + b</pre><pre>x = add(2, 3)</pre><pre>print(x)</pre><p><strong>Output</strong></p><pre>None</pre><p>Since the function didn’t explicitly return anything, Python automatically returns None.</p><h3>print() vs return()</h3><p>Many beginners confuse these two.</p><h3>Using print()</h3><pre>def add(a, b):<br>    print(a + b)</pre><pre>add(2, 3)</pre><p>This only displays the result.</p><h3>Using return</h3><pre>def add(a, b):<br>    return a + b</pre><pre>result = add(2, 3)<br>print(result)</pre><p>This gives the value back so it can be reused later.</p><p>print()returnDisplays outputSends value backCannot be reusedCan be stored and reusedMainly for debuggingUsed in real programs</p><h3>Returning Multiple Values</h3><p>Python allows multiple return values.</p><pre>def get_info():<br>    return &quot;Faizan&quot;, 22</pre><pre>name, age = get_info()</pre><pre>print(name)<br>print(age)</pre><p>Behind the scenes, Python actually returns a tuple.</p><pre>(&quot;Faizan&quot;, 22)</pre><h3>Default Parameters</h3><p>Default values make parameters optional.</p><pre>def greet(name=&quot;Guest&quot;):<br>    print(name)</pre><pre>greet()<br>greet(&quot;Faizan&quot;)</pre><p><strong>Output</strong></p><pre>Guest<br>Faizan</pre><h3>Positional Arguments</h3><p>Arguments are matched according to their position.</p><pre>def introduce(name, age):<br>    print(name, age)</pre><pre>introduce(&quot;Faizan&quot;, 22)</pre><p>Order matters.</p><h3>Keyword Arguments</h3><p>Instead of relying on order, specify parameter names.</p><pre>introduce(age=22, name=&quot;Faizan&quot;)</pre><p>Now order doesn’t matter.</p><h3>Arbitrary Positional Arguments (*args)</h3><p>Sometimes you don’t know how many arguments users will provide.</p><pre>def add(*args):<br>    print(args)</pre><pre>add(1, 2, 3, 4)</pre><p><strong>Output</strong></p><pre>(1, 2, 3, 4)</pre><p>args is stored as a tuple.</p><p>Practical example:</p><pre>def add(*args):<br>    return sum(args)</pre><pre>print(add(1, 2, 3))</pre><p><strong>Output</strong></p><pre>6</pre><h3>Arbitrary Keyword Arguments (**kwargs)</h3><p>Accept any number of named arguments.</p><pre>def info(**kwargs):<br>    print(kwargs)</pre><pre>info(name=&quot;Faizan&quot;, age=22)</pre><p><strong>Output</strong></p><pre>{&#39;name&#39;: &#39;Faizan&#39;, &#39;age&#39;: 22}</pre><p>kwargs is stored as a dictionary.</p><h3>Local Variables</h3><p>Variables created inside a function are local.</p><pre>def test():<br>    x = 10</pre><pre>print(x)</pre><p><strong>Output</strong></p><pre>NameError</pre><p>The variable exists only inside the function.</p><h3>Global Variables</h3><p>Variables declared outside functions are global.</p><pre>x = 100</pre><pre>def show():<br>    print(x)</pre><pre>show()</pre><p><strong>Output</strong></p><pre>100</pre><h3>The global Keyword</h3><p>To modify a global variable inside a function:</p><pre>x = 10</pre><pre>def change():<br>    global x<br>    x = 20</pre><pre>change()</pre><pre>print(x)</pre><p><strong>Output</strong></p><pre>20</pre><p>Without global, Python creates a new local variable instead.</p><h3>Understanding the LEGB Rule</h3><p>When Python searches for a variable, it follows this order:</p><ul><li><strong>L</strong> → Local</li><li><strong>E</strong> → Enclosing</li><li><strong>G</strong> → Global</li><li><strong>B</strong> → Built-in</li></ul><p>Example:</p><pre>x = 100</pre><pre>def show():<br>    x = 10<br>    print(x)</pre><pre>show()</pre><p><strong>Output</strong></p><pre>10</pre><p>Python finds the local variable first.</p><h3>Nested Functions</h3><p>Functions can contain other functions.</p><pre>def outer():</pre><pre>    def inner():<br>        print(&quot;Hello&quot;)</pre><pre>    inner()</pre><pre>outer()</pre><p>Nested functions are useful for organizing logic and implementing closures.</p><h3>Closures (Interview Favorite)</h3><p>A closure remembers variables from its outer function even after that function has finished executing.</p><pre>def outer():<br>    x = 10</pre><pre>    def inner():<br>        print(x)</pre><pre>    return inner</pre><pre>func = outer()<br>func()</pre><p><strong>Output</strong></p><pre>10</pre><p>Closures are widely used in decorators and functional programming.</p><h3>Lambda Functions</h3><p>A lambda is a small anonymous function.</p><p>Normal function:</p><pre>def square(x):<br>    return x * x</pre><p>Lambda version:</p><pre>square = lambda x: x * x</pre><pre>print(square(5))</pre><p><strong>Output</strong></p><pre>25</pre><p>Multiple parameters:</p><pre>add = lambda a, b: a + b</pre><pre>print(add(3, 7))</pre><h3>Recursion</h3><p>A recursive function calls itself.</p><pre>def countdown(n):</pre><pre>    if n == 0:<br>        return</pre><pre>    print(n)<br>    countdown(n - 1)</pre><pre>countdown(3)</pre><p><strong>Output</strong></p><pre>3<br>2<br>1</pre><h3>Base Case</h3><p>Every recursive function must have a stopping condition.</p><pre>if n == 0:<br>    return</pre><p>Without it, Python eventually throws:</p><pre>RecursionError</pre><h3>Functions are First-Class Objects</h3><p>In Python, functions are objects.</p><p>You can:</p><ul><li>Store them in variables.</li><li>Pass them to other functions.</li><li>Return them from functions.</li></ul><pre>def greet():<br>    print(&quot;Hello&quot;)</pre><pre>x = greet</pre><pre>x()</pre><h3>Higher-Order Functions</h3><p>A higher-order function accepts another function or returns one.</p><pre>def execute(func):<br>    func()</pre><pre>def hello():<br>    print(&quot;Hello&quot;)</pre><pre>execute(hello)</pre><h3>map()</h3><p>Apply a function to every element.</p><pre>nums = [1, 2, 3]</pre><pre>result = map(lambda x: x * 2, nums)</pre><pre>print(list(result))</pre><p><strong>Output</strong></p><pre>[2, 4, 6]</pre><h3>filter()</h3><p>Keep only elements that satisfy a condition.</p><pre>nums = [1, 2, 3, 4]</pre><pre>result = filter(lambda x: x % 2 == 0, nums)</pre><pre>print(list(result))</pre><p><strong>Output</strong></p><pre>[2, 4]</pre><h3>Function Annotations (Type Hints)</h3><p>Type hints improve readability and editor support.</p><pre>def add(a: int, b: int) -&gt; int:<br>    return a + b</pre><p>They don’t enforce types.</p><pre>add(&quot;a&quot;, &quot;b&quot;)</pre><p>This still works because Python is dynamically typed.</p><h3>Docstrings</h3><p>A docstring explains what a function does.</p><pre>def add(a, b):<br>    &quot;&quot;&quot;<br>    Returns the sum of two numbers.<br>    &quot;&quot;&quot;<br>    return a + b</pre><p>View it using:</p><pre>help(add)</pre><p>Good documentation makes code easier to understand and maintain.</p><h3>Mutable Default Argument Trap (Famous Interview Question)</h3><p>Incorrect approach:</p><pre>def add_item(item, items=[]):<br>    items.append(item)<br>    return items</pre><pre>print(add_item(1))<br>print(add_item(2))</pre><p><strong>Output</strong></p><pre>[1]<br>[1, 2]</pre><p>The same list is reused every time.</p><p>Correct approach:</p><pre>def add_item(item, items=None):</pre><pre>    if items is None:<br>        items = []</pre><pre>    items.append(item)</pre><pre>    return items</pre><p>Always use None instead of mutable objects as default arguments.</p><h3>Using *args and **kwargs Together</h3><pre>def func(*args, **kwargs):<br>    print(args)<br>    print(kwargs)</pre><pre>func(1, 2, 3, name=&quot;Faizan&quot;)</pre><p><strong>Output</strong></p><pre>(1, 2, 3)<br>{&#39;name&#39;: &#39;Faizan&#39;}</pre><h3>What Happens Internally When a Function Runs?</h3><p>When you call:</p><pre>add(2, 3)</pre><p>Python performs these steps:</p><ol><li>Creates a new stack frame.</li><li>Allocates local variables.</li><li>Executes the function body.</li><li>Returns the result.</li><li>Removes the stack frame.</li></ol><p>Each function call has its own independent stack frame. This is especially important for recursion.</p><h3>Common Interview Questions</h3><h3>1. Difference between parameter and argument?</h3><ul><li>Parameter → Variable in the function definition.</li><li>Argument → Actual value passed during the function call.</li></ul><h3>2. Difference between print() and return()?</h3><ul><li>print() displays a value.</li><li>return sends a value back to the caller.</li></ul><h3>3. What is recursion?</h3><p>A function calling itself until a base case is reached.</p><h3>4. What is a closure?</h3><p>An inner function that remembers variables from its enclosing scope.</p><h3>5. What is *args?</h3><p>Collects extra positional arguments into a tuple.</p><h3>6. What is **kwargs?</h3><p>Collects extra keyword arguments into a dictionary.</p><h3>7. What is the LEGB Rule?</h3><p>Python searches variables in this order:</p><ul><li>Local</li><li>Enclosing</li><li>Global</li><li>Built-in</li></ul><h3>8. Are functions objects in Python?</h3><p>Yes.</p><p>Functions are first-class objects.</p><h3>9. What is a lambda function?</h3><p>A small anonymous one-line function.</p><h3>10. Why are mutable default arguments dangerous?</h3><p>Because the same object is reused across multiple function calls.</p><h3>One-Minute Revision</h3><p>✅ Functions are reusable blocks of code.</p><p>✅ Use def to create functions.</p><p>✅ Parameters are placeholders.</p><p>✅ Arguments are actual values.</p><p>✅ return gives values back.</p><p>✅ print() only displays output.</p><p>✅ Default parameters make arguments optional.</p><p>✅ *args stores extra positional arguments in a tuple.</p><p>✅ **kwargs stores extra keyword arguments in a dictionary.</p><p>✅ Local variables exist only inside functions.</p><p>✅ Global variables exist outside functions.</p><p>✅ Python follows the <strong>LEGB</strong> rule for variable lookup.</p><p>✅ Lambda functions are anonymous one-line functions.</p><p>✅ Closures remember outer variables.</p><p>✅ Recursive functions must always have a base case.</p><p>✅ Functions are first-class objects.</p><p>✅ Never use mutable objects like [] as default arguments.</p><h3>Final Thoughts</h3><p>Functions are much more than a way to avoid repeating code. They are the building blocks of every Python application. Once you’re comfortable with functions, concepts like object-oriented programming, decorators, generators, APIs, and frameworks such as Django or Flask become significantly easier to learn.</p><p>If you’re serious about mastering Python, spend time writing your own functions, experimenting with parameters, recursion, and higher-order functions. The more you practice, the more natural they become.</p><p>In the next article of this series, we’ll dive deeper into another core Python concept and continue building a strong foundation — one step at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b610213ab37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Variables: The Complete Guide You’ll Wish You Had Earlier]]></title>
            <link>https://medium.com/@ibrahim.popatiya3/python-variables-the-complete-guide-youll-wish-you-had-earlier-02deb3fc0162?source=rss-95fee98c3911------2</link>
            <guid isPermaLink="false">https://medium.com/p/02deb3fc0162</guid>
            <dc:creator><![CDATA[Ibrahim Popatiya]]></dc:creator>
            <pubDate>Fri, 19 Jun 2026 15:53:49 GMT</pubDate>
            <atom:updated>2026-06-19T15:53:49.751Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Day 1 of my Python Deep Dive series — one concept, every day, explained like a human.</em></p><p>If someone asks you, “What is a variable in Python?” and you answer “a container that stores data” — you’re not wrong, but you’re not entirely right either. And that half-truth? It trips people up in interviews, debugging sessions, and real-world code all the time.</p><p>Today, let’s fix that. Let’s talk about Python variables — <strong>properly</strong>.</p><h3>What Is a Variable, Really?</h3><p>Most tutorials say: <em>“A variable is a box that holds a value.”</em></p><p>That’s the simplified version. Here’s what actually happens:</p><p><strong>A variable is a name that refers to an object stored in memory.</strong></p><p>It’s not a box. It’s a <strong>label</strong> — a sticky note you slap onto an object.</p><pre>name = &quot;Faizan&quot;<br>age = 22</pre><p>Here, name doesn&#39;t <em>contain</em> the string &quot;Faizan&quot;. It <strong>points to</strong> a string object that lives somewhere in memory. Same with age — it points to the integer object 22.</p><p>Why does this distinction matter? Keep reading. It’ll click when we get to mutable objects.</p><h3>Why Bother With Variables?</h3><p>Imagine you’re building a greeting system. Without variables:</p><pre>print(&quot;Hello, Faizan! Welcome to Python.&quot;)<br>print(&quot;Faizan, your profile has been created.&quot;)<br>print(&quot;Thank you, Faizan!&quot;)</pre><p>Now the client says: <em>“Actually, it’s not Faizan. It’s Ahmed.”</em></p><p>You’re editing three lines. In a real app, that could be three hundred.</p><p>With variables:</p><pre>user_name = &quot;Faizan&quot;</pre><pre>print(f&quot;Hello, {user_name}! Welcome to Python.&quot;)<br>print(f&quot;{user_name}, your profile has been created.&quot;)<br>print(f&quot;Thank you, {user_name}!&quot;)</pre><p>Change one line, and everything updates. That’s the power of variables:</p><ul><li><strong>Reuse</strong> data without repeating yourself</li><li><strong>Update</strong> values in one place</li><li><strong>Readability</strong> — your code tells a story</li></ul><h3>Creating Variables: No Ceremony Needed</h3><p>Coming from Java or C++? You’re used to this:</p><pre>int age = 25;<br>String name = &quot;Faizan&quot;;</pre><p>Python doesn’t care about type declarations:</p><pre>age = 25<br>name = &quot;Faizan&quot;</pre><p>You assign a value, and Python figures out the type. This is called <strong>dynamic typing</strong>, and it’s one of the reasons Python feels so fast to write.</p><p>You can even reassign a variable to a completely different type:</p><pre>x = 10        # x points to an integer<br>x = &quot;hello&quot;   # now x points to a string<br>x = 3.14      # now x points to a float</pre><p>No errors. No complaints. Python just rolls with it.</p><h3>The Naming Rules (Break These and Python Breaks You)</h3><p><strong>Allowed:</strong></p><pre>first_name = &quot;Faizan&quot;<br>_private_var = 42<br>age2 = 25</pre><p><strong>Not allowed:</strong></p><pre>2cool = &quot;nope&quot;       # can&#39;t start with a number<br>my-name = &quot;broken&quot;   # hyphens aren&#39;t allowed<br>class = &quot;reserved&quot;   # &#39;class&#39; is a keyword</pre><p><strong>Quick rule of thumb:</strong> Start with a letter or underscore, then use letters, numbers, and underscores. That’s it.</p><h3>Naming Conventions That Make You Look Professional</h3><p>Python’s style guide (PEP 8) has opinions:</p><pre># Variables and functions: snake_case<br>student_name = &quot;Faizan&quot;<br>total_marks = 95</pre><pre># Constants: SCREAMING_SNAKE_CASE<br>MAX_RETRIES = 3<br>PI = 3.14159<br>DATABASE_URL = &quot;localhost:5432&quot;</pre><p>And please — <strong>use meaningful names</strong>:</p><pre># This tells you nothing<br>x = 10<br>y = 20<br>z = x * y</pre><pre># This tells a story<br>price = 10<br>quantity = 20<br>total_cost = price * quantity</pre><p>Future-you will thank present-you.</p><h3>Multiple Assignments: Python’s Party Tricks</h3><p>Assign multiple variables in one line:</p><pre>a, b, c = 1, 2, 3<br>print(a)  # 1<br>print(b)  # 2<br>print(c)  # 3</pre><p>Assign the same value to multiple variables:</p><pre>x = y = z = 100<br>print(x, y, z)  # 100 100 100</pre><h3>Swapping Variables (Interview Classic)</h3><p>In most languages, you need a temporary variable:</p><pre>a = 10<br>b = 20</pre><pre>temp = a<br>a = b<br>b = temp</pre><p>Python? One line:</p><pre>a = 10<br>b = 20<br>a, b = b, a</pre><pre>print(a)  # 20<br>print(b)  # 10</pre><p>This works because Python evaluates the right side completely before assigning. Clean, elegant, and interviewers love asking about it.</p><h3>Type Checking: type() and id()</h3><p>Curious what type a variable points to?</p><pre>x = 42<br>print(type(x))   # &lt;class &#39;int&#39;&gt;</pre><pre>y = &quot;hello&quot;<br>print(type(y))   # &lt;class &#39;str&#39;&gt;</pre><pre>z = 3.14<br>print(type(z))   # &lt;class &#39;float&#39;&gt;</pre><pre>w = True<br>print(type(w))   # &lt;class &#39;bool&#39;&gt;</pre><p>Want to see where an object lives in memory?</p><pre>x = 10<br>y = x</pre><pre>print(id(x))  # e.g., 140234866412112<br>print(id(y))  # same number!</pre><p>Same id means they&#39;re pointing to the <strong>exact same object</strong>. Not a copy — the same one.</p><h3>== vs is (The Interview Question That Catches Everyone)</h3><p>This is where most people get confused. Let’s clear it up with one example:</p><pre>a = [1, 2, 3]<br>b = [1, 2, 3]</pre><pre>print(a == b)   # True  — same values<br>print(a is b)   # False — different objects in memory</pre><p>Now compare:</p><pre>a = [1, 2, 3]<br>b = a</pre><pre>print(a == b)   # True  — same values<br>print(a is b)   # True  — same object!</pre><p><strong>The rule:</strong></p><ul><li>== asks: <em>&quot;Do these have the same value?&quot;</em></li><li>is asks: <em>&quot;Are these literally the same object in memory?&quot;</em></li></ul><p>Use == for comparisons. Use is mainly for checking None:</p><pre>if result is None:<br>    print(&quot;No result found&quot;)</pre><h3>Mutable vs Immutable: The Concept That Changes Everything</h3><p>This is the <strong>single most important thing</strong> about Python variables. If you understand this, you understand half of Python’s quirks.</p><h3>Immutable Objects (Can’t Be Changed After Creation)</h3><p>int, float, str, bool, tuple</p><pre>x = &quot;hello&quot;<br>print(id(x))    # let&#39;s say 140234866412112</pre><pre>x = x + &quot; world&quot;<br>print(id(x))    # different id! — a NEW object was created</pre><p>You didn’t modify the original string. Python created a <strong>brand new</strong> string &quot;hello world&quot; and pointed x to it. The old &quot;hello&quot; is now orphaned (and will be garbage collected).</p><h3>Mutable Objects (Can Be Changed In Place)</h3><p>list, dict, set</p><pre>nums = [1, 2, 3]<br>print(id(nums))    # some id</pre><pre>nums.append(4)<br>print(id(nums))    # SAME id — the object was modified in place<br>print(nums)        # [1, 2, 3, 4]</pre><p>Same object, new contents. This is why the next section is so critical.</p><h3>The Trap: Assignment with Mutable Objects</h3><p><strong>This is the #1 Python gotcha. Read carefully.</strong></p><pre>a = [1, 2, 3]<br>b = a</pre><pre>b.append(4)</pre><pre>print(a)  # [1, 2, 3, 4]  &lt;-- Wait, what?!<br>print(b)  # [1, 2, 3, 4]</pre><p>Both a and b point to the <strong>same list object</strong>. When you mutate through b, you see the change through a too.</p><p>Visually:</p><pre>a ──┐<br>    ├──▶ [1, 2, 3, 4]<br>b ──┘</pre><p><strong>If you want an independent copy:</strong></p><pre>a = [1, 2, 3]<br>b = a.copy()        # or list(a) or a[:]</pre><pre>b.append(4)</pre><pre>print(a)  # [1, 2, 3]   — untouched!<br>print(b)  # [1, 2, 3, 4]</pre><p>Now they’re separate objects:</p><pre>a ──▶ [1, 2, 3]<br>b ──▶ [1, 2, 3, 4]</pre><h3>A Sneaky Variation of the Same Trap</h3><pre>x = y = []</pre><pre>x.append(1)<br>print(y)  # [1]  — surprise!</pre><p>Same thing. x = y = [] makes both names point to <strong>one</strong> empty list.</p><h3>Deleting Variables and Garbage Collection</h3><p>You can remove a variable with del:</p><pre>x = 42<br>del x</pre><pre>print(x)  # NameError: name &#39;x&#39; is not defined</pre><p>del doesn&#39;t delete the <em>object</em> — it removes the <em>name</em>. If no names point to an object anymore, Python&#39;s <strong>garbage collector</strong> cleans it up automatically.</p><p>Unlike C or C++, you never manually free memory. Python handles it for you.</p><h3>Let’s Build Something: A Mini Variable Playground</h3><p>Try running this to solidify every concept:</p><pre># --- Dynamic typing ---<br>data = 100<br>print(f&quot;data = {data}, type = {type(data).__name__}&quot;)</pre><pre>data = &quot;Now I&#39;m a string&quot;<br>print(f&quot;data = {data}, type = {type(data).__name__}&quot;)</pre><pre># --- Identity vs equality ---<br>list_a = [1, 2, 3]<br>list_b = [1, 2, 3]<br>list_c = list_a</pre><pre>print(f&quot;\nlist_a == list_b? {list_a == list_b}&quot;)   # True<br>print(f&quot;list_a is list_b? {list_a is list_b}&quot;)     # False<br>print(f&quot;list_a is list_c? {list_a is list_c}&quot;)     # True</pre><pre># --- Mutation through reference ---<br>list_c.append(99)<br>print(f&quot;\nAfter list_c.append(99):&quot;)<br>print(f&quot;list_a = {list_a}&quot;)  # [1, 2, 3, 99]<br>print(f&quot;list_c = {list_c}&quot;)  # [1, 2, 3, 99]</pre><pre># --- Safe copy ---<br>list_d = list_a.copy()<br>list_d.append(999)<br>print(f&quot;\nAfter copying and modifying list_d:&quot;)<br>print(f&quot;list_a = {list_a}&quot;)  # unchanged<br>print(f&quot;list_d = {list_d}&quot;)  # has 999</pre><pre># --- Swapping ---<br>x, y = &quot;first&quot;, &quot;second&quot;<br>x, y = y, x<br>print(f&quot;\nAfter swap: x = {x}, y = {y}&quot;)</pre><p>Run it. Tweak it. Break it. That’s how you learn.</p><h3>Quick Reference Cheat Sheet</h3><p>ConceptSyntaxNotesCreate variablex = 10No type declaration neededCheck typetype(x)Returns the classCheck identityid(x)Memory-related identifierCompare valuesa == bUse for most comparisonsCompare identitya is bUse mainly for None checksMultiple assigna, b = 1, 2Unpack in one lineSwapa, b = b, aNo temp variable neededCopy listb = a.copy()Creates independent copyDeletedel xRemoves the name binding</p><h3>Interview Corner: 6 Questions You Must Nail</h3><ol><li><strong>“What is a variable in Python?”</strong> — A name that refers to an object in memory, not a container.</li><li><strong>“Is Python statically or dynamically typed?”</strong> — Dynamically typed. Variables can point to any type.</li><li><strong>“Difference between </strong><strong>== and </strong><strong>is?&quot;</strong> — == compares values, is compares object identity.</li><li><strong>“What are mutable and immutable types?”</strong> — Mutable (list, dict, set) can change in place. Immutable (int, str, tuple, bool, float) cannot.</li><li><strong>“What happens when you do </strong><strong>b = a with a list?&quot;</strong> — Both variables reference the same list. Changes through one are visible through the other.</li><li><strong>“How do you safely copy a list?”</strong> — a.copy(), list(a), or a[:].</li></ol><h3>Wrapping Up</h3><p>Python variables aren’t boxes. They’re <strong>labels pointing to objects</strong>. Once you internalize that mental model, everything else — mutability, identity checks, copying behavior — falls into place naturally.</p><p>Tomorrow, we’ll dive into <strong>Data Types in Python</strong> — going deeper into int, float, str, bool, and beyond.</p><p>If this helped you, give it a clap and follow along. One concept a day, and you’ll have a rock-solid Python foundation in weeks.</p><p><em>This is Day 1 of my Python Deep Dive series. Follow me to catch every post.</em></p><p><em>Got questions? Drop them in the comments — I read every single one.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02deb3fc0162" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“What Python Really Is: The Hidden Core Explained Simply”]]></title>
            <link>https://medium.com/@ibrahim.popatiya3/what-python-really-is-the-hidden-core-explained-simply-2eae9f72ec9f?source=rss-95fee98c3911------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eae9f72ec9f</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[basics-of-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Ibrahim Popatiya]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 02:34:38 GMT</pubDate>
            <atom:updated>2025-09-16T02:34:38.871Z</atom:updated>
            <content:encoded><![CDATA[<p>Everyone knows Python as an <em>easy</em> language, but very few truly understand what sets it apart from all the others.</p><p>I’ve been using Python for a while — building projects, reading docs, solving problems — but one day I realized something: I knew <em>how</em> to use Python, but I didn’t really understand its <strong>core nature</strong>. Why is Python called an <strong>interpreted language</strong>? Why don’t we just compile it like C or C++? And what exactly makes it “high-level”?</p><p>Turns out, this isn’t just my blind spot. Many developers can write Python code flawlessly but have only a vague idea of why it works the way it does. That’s why I decided to write this post — to break down these <strong>fundamental concepts</strong> in plain, simple words.</p><p>Ever wondered:</p><ul><li>Why is Python called <em>interpreted</em>?</li><li>Why not just use a <em>compiler</em>?</li><li>What does <em>high-level language</em> actually mean?</li></ul><p>Let’s find out together 🐍👇</p><h3>What is Python?</h3><p>Python is a <strong>high-level, interpreted programming language</strong> created by <strong>Guido van Rossum in 1991</strong>.</p><p>Sure, you may have seen this definition before — but what does it <strong>actually mean under the hood</strong>?</p><h3>Why is Python called an Interpreted Language?</h3><p>Think of Python like having a personal translator sitting next to you:</p><ul><li>You say one sentence → the translator immediately translates it.</li><li>You say another sentence → it gets translated instantly.</li></ul><p>Python works the same way. It doesn’t translate your whole program at once. Instead, it reads your code <strong>line by line</strong>, executes it, and stops immediately if there’s an error.</p><p>This is what makes Python so friendly for beginners — you see the results of your code instantly.</p><h3>What is a Compiler?</h3><p>A compiler is a different kind of translator. Imagine someone who:</p><ol><li>Reads your <strong>entire book</strong> first.</li><li>Translates it fully into another language.</li><li>Only then gives you the result.</li></ol><p>In programming terms, a compiler processes the entire program in one go and creates a <strong>standalone executable file</strong>. Once compiled, you can run the program as many times as you like without needing the compiler again.</p><h3>Why Python is Interpreted and Not Compiled?</h3><p>Languages like C or C++ are compiled directly into <strong>machine code</strong>, which the CPU executes. Python takes a different route. When you run a Python script:</p><ul><li>Your code is first turned into <strong>bytecode</strong>.</li><li>The <strong>Python Virtual Machine (PVM)</strong> executes the bytecode line by line.</li></ul><p>Think of bytecode as a middle ground — more readable by machines than your Python code, but not tied to any specific CPU.</p><p>This is why Python is called an <strong>interpreted language</strong>. It’s flexible, beginner-friendly, and lets you test ideas immediately. The trade-off? It’s usually slower than compiled languages — but the ease of use more than makes up for it.</p><h3>Why Python is Called a High-Level Language?</h3><p>Python is “high-level” because it’s closer to <strong>human language</strong> than machine language. You don’t need to manage memory, CPU registers, or low-level instructions — Python handles that for you.</p><p>Example:</p><pre>print(&quot;Hello, World!&quot;)</pre><p>In Python, this prints a message in <strong>one simple line</strong>. Compare that with C, where you need multiple lines for the same task:</p><pre>#include &lt;stdio.h&gt;<br>int main() {<br>    printf(&quot;Hello, World!\\n&quot;);<br>    return 0;<br>}</pre><p>Or even lower-level Assembly, which takes dozens of instructions just to display text.</p><h3>Other Levels of Programming Languages</h3><p>Programming languages can be categorized by <strong>how close they are to humans or machines</strong>:</p><p><strong>Low-Level Languages</strong></p><ul><li><strong>Machine Code (binary 0s and 1s)</strong> → CPU understands directly.</li><li><strong>Assembly Language</strong> → symbolic representation of machine instructions.</li><li>Very fast, but hard to write and read.</li></ul><p><strong>Mid-Level Languages</strong></p><ul><li>Example: <strong>C</strong></li><li>Some abstraction, but still gives access to hardware details.</li></ul><p><strong>High-Level Languages</strong></p><ul><li>Example: <strong>Python, Java, Ruby</strong></li><li>Close to human language, easy to read and write.</li><li>Abstracts away memory management, CPU instructions, and OS-level details.</li></ul><h3>Why Python is High-Level and Interpreted?</h3><p>Python is <strong>high-level</strong> because it hides all the complex machine details and lets you focus on <strong>what you want to do</strong>, not <strong>how the CPU does it</strong>.</p><p>It is <strong>interpreted</strong> because the Python interpreter executes code <strong>line by line at runtime</strong>. You don’t need to compile the whole program first — this makes debugging easier, testing faster, and code more portable.</p><h3>Final Thoughts</h3><p>Understanding Python’s <strong>high-level and interpreted nature</strong> is like peeking behind the curtain. Every line you write is being translated live by Python’s virtual translator — making coding feel almost like a conversation with your computer.</p><p>If this gave you a fresh perspective on Python, stay tuned — my next blog will dive deeper into <strong>how Python actually executes your code step by step</strong>, including some cool tricks most developers never notice.</p><p>Until then, keep coding, keep exploring, and remember: <strong>the magic is in understanding how the language thinks!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eae9f72ec9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>