<?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: Lilian Mwaura</title>
    <description>The latest articles on DEV Community by Lilian Mwaura (@lilianmwaura).</description>
    <link>https://dev.to/lilianmwaura</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F899992%2Ff16be256-8f72-4b4b-8659-9607f5faee4a.jpeg</url>
      <title>DEV Community: Lilian Mwaura</title>
      <link>https://dev.to/lilianmwaura</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lilianmwaura"/>
    <language>en</language>
    <item>
      <title>Division, Floor Division and Modulus - Python Arithmetic Operators every beginner should know.</title>
      <dc:creator>Lilian Mwaura</dc:creator>
      <pubDate>Tue, 02 Aug 2022 09:26:04 +0000</pubDate>
      <link>https://dev.to/lilianmwaura/division-floor-division-and-modulus-python-arithmetic-operators-every-beginner-should-know-13i8</link>
      <guid>https://dev.to/lilianmwaura/division-floor-division-and-modulus-python-arithmetic-operators-every-beginner-should-know-13i8</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is an Operator?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Operators are used to perform operations on variables and values.&lt;br&gt;
In python, Operators are classified into different categories based on the kind of operations they perform:&lt;br&gt;
They include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Assignment Operators&lt;/li&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Identity operators&lt;/li&gt;
&lt;li&gt;Membership operators&lt;/li&gt;
&lt;li&gt;Bitwise operators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Arithmetic Operators&lt;/strong&gt; &lt;br&gt;
Arithmetic operators are used with numeric values to perform common mathematical operations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operator&lt;/strong&gt;  &lt;strong&gt;Name&lt;/strong&gt;         &lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; +         Addition             x + y &lt;/li&gt;
&lt;li&gt; -         Subtraction      x - y &lt;/li&gt;
&lt;li&gt; *         Multiplication   x * y &lt;/li&gt;
&lt;li&gt; /         Division             x / y &lt;/li&gt;
&lt;li&gt; %         Modulus              x % y &lt;/li&gt;
&lt;li&gt;**         Exponentiation   x ** y
&lt;/li&gt;
&lt;li&gt;//         Floor division   x // y&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Difference between Division, Modulus and Floor Division&lt;/strong&gt;&lt;br&gt;
All these operators are quite interesting because they all perform division, but print different results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Division (/) - basically gives out the result of a division.
a = 5
b = 2 
print(5/2)
# result will be 2.5

#Floor Division (//) - Provides the lower-bound of an integral division
a = 5
b = 2
print(5//2)
# result will be 2, the decimal is cut off returning only the whole number

#Modulus(%) - Computes the reminder of a division,which is the 'leftover' of an integral division.
a= 5
b=2
print(5%2)
#result will be 1, which is the 'leftover' integer after the division

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

&lt;/div&gt;



&lt;p&gt;First time I learnt all these operations and the different results they print out, I did not quite understand the essence of knowing all these. &lt;/p&gt;

&lt;p&gt;But understanding operators comes in handy when solving problems in Python. &lt;/p&gt;

&lt;p&gt;For example, modulus is important in finding out even and odd numbers in python. &lt;br&gt;
See the example below : &lt;/p&gt;

&lt;h3&gt;
  
  
  How to determine even and odd numbers using modulus(%)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;n % 2 == 1 
# when n is divided by 2 and the output has a reminder of 1 which means that the number is odd.

n % 2 == 0
# when n is divided by 2 and the is 0, meaning the number is divisible by 2 then the result is an even number.



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

&lt;/div&gt;



&lt;p&gt;Hope you learnt something.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>python</category>
      <category>operators</category>
      <category>beginners</category>
      <category>modulus</category>
    </item>
  </channel>
</rss>
