<?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 Ravi on Medium]]></title>
        <description><![CDATA[Stories by Ravi on Medium]]></description>
        <link>https://medium.com/@learnwithravi06?source=rss-c01cd9d4b494------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QD5xPOWimXjUramvLRG_pA.jpeg</url>
            <title>Stories by Ravi on Medium</title>
            <link>https://medium.com/@learnwithravi06?source=rss-c01cd9d4b494------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:52:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@learnwithravi06/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[Understanding Python Modulo Operator(%) in Python]]></title>
            <link>https://medium.com/@learnwithravi06/understanding-python-modulo-operator-in-python-6b78967e2cf2?source=rss-c01cd9d4b494------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b78967e2cf2</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Ravi]]></dc:creator>
            <pubDate>Sun, 22 Feb 2026 14:19:46 GMT</pubDate>
            <atom:updated>2026-02-22T14:19:46.673Z</atom:updated>
            <content:encoded><![CDATA[<h4>The modulo operator % in Python is one of those operators that can be surprisingly tricky, especially when negative numbers are involved. if you’ve ever wondered why -7 % 3 gives 2 instead of -1. This article will break it down in simple terms.</h4><p><strong>What is the modulo operator?</strong></p><p>The modulo operator returns the <strong>remainder</strong> of a division.</p><pre>moduloPositive = 7 % 3 #modulo with positive numbers<br>print(moduloPositive) # Output: 1</pre><p><strong>Modulo with Negative Numbers</strong></p><p>This is where Python behaves differently from some other languages.</p><pre>moduloNegative = -7 % 3 #modulo with a negative number<br>print(moduloNegative) # Output: 2</pre><p>You might expect -1 because -7 ÷ 3 = -2 remainder -1. But Python actually gives 2.</p><p><strong>Why?</strong></p><p>In Python, the result of the modulo operation has the <strong>same sign as the divisor</strong> (the second operand), not the dividend.</p><p>The Fundamental Formula:</p><p>In Python, the modulo operator is mathematically linked to the floor division operator (//) by the following identity.</p><p>r = a — (b * (a // b))</p><p>where:</p><p>a = -7 <br>b = 3</p><p>Calculate Floor Division:</p><p>First, we find the result of -7 // 3. As we discussed in the previous article <a href="https://medium.com/@ravinerusu06/understanding-floor-division-in-python-985e790fdbb8">https://medium.com/@ravinerusu06/understanding-floor-division-in-python-985e790fdbb8</a> , floor division rounds toward negative infinity.</p><p>-7 / 3 = -2.333… So floor value is -7 // 3 = -3</p><p>Now substitute values into the formula to find r:</p><p>r = -7 — (3 * -3)<br>r = -7 — (-9)<br>r = -7 + 9<br>r = 2</p><p>Conclusion:</p><p>The result of -7 % 3 is 2, because Python calculates the remainder based on floor division (-7//3 = -3), which results in the formula -7-(3*-3) = 2.</p><p>#Python #Programming #Coding #Developers</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b78967e2cf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Floor Division in Python]]></title>
            <link>https://medium.com/@learnwithravi06/understanding-floor-division-in-python-985e790fdbb8?source=rss-c01cd9d4b494------2</link>
            <guid isPermaLink="false">https://medium.com/p/985e790fdbb8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ravi]]></dc:creator>
            <pubDate>Sun, 22 Feb 2026 11:14:58 GMT</pubDate>
            <atom:updated>2026-02-22T14:02:38.226Z</atom:updated>
            <content:encoded><![CDATA[<h4>When working with numbers in Python, division behaves differently depending on the operator you use. One operator that often surprises beginners is the floor division operator (//).</h4><p>Here’s a simple example demonstrating floor division with positive and negative numbers:</p><pre>floorPositive = 10 // 3 # floor division with positive numbers<br>print(floorPositive) # output: 3<br><br>floorNegative = -10 // 3 # floor division with negative numbers<br>print(floorNegative) # output: -4</pre><p>Why does this happen?</p><p>The floor division operator(//) always rounds down to the nearest whole number (toward negative infinity).</p><p>For positive numbers, rounding down simply means removing the decimal part:</p><p>10 / 3 = 3.33 → rounds down to 3</p><p>For negative numbers, “rounding down” means moving to the next lower integer — which is more negative.</p><p>-10 / 3 = -3.33 → rounds down to -4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RnuCKrNkxK_S14s7682iWQ.png" /></figure><p>That’s why:</p><p>-10 // 3 = -4</p><p>Understanding this behavior is essential when working with negative values, loops, indexing, or mathematical logic in Python. A small misunderstanding can lead to bugs in your programs.</p><p>#Python #Programming #Coding #Developers</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=985e790fdbb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>