DAY 2 - Arithmetic Operators

Let's start with arthritic operations. x = 25 y = 10 Operation What it returns Output x + y Sum of x and y 35 x - y Difference of x and y 15 -x Changed sign of x -1 * 25 = -25 +x Identity of x +1 * 25 = 25 x * y Product of x and y 250 x / y Quotient of x and y 2.5 hashtagyour quotient will always be returned as a float, even if you use two integers x // y Quotient from floor division of x and y 2 x % y Remainder of x / y 5 x ** y x to the y power 9,53,67,43,16,40,625 Some interesting observations: a = -60 b = 13 > a/b -4.615384615384615 > a//b -5 > a = -a > a/b 4.615384615384615 > a//b 4 Python Math Confusion ############################ When performing math operations in Python, we should follow BEDMAS,not PEMDAS. That's my observation. Let's try and let me know , if this rule fails.


Compound Operation   What it returns                        Output y += 1                      add then assign value                    11 (y = y + 1) y -= 1                       subtract then assign value                          9 y *= 2                       multiply then assign value                          20 y /= 3                       divide then assign value                              3.333 y // = 3                     floor divide then assign value                      3 y **= 2                      increase to the power of then assign value 100 y %= 3                      return remainder then assign value             1


RR hashtagDay2 hashtagPython hashtagArithmaticOperators hashtagDataScience hashtagHappyLearning hashtagWeLearnEveryday

Comments

Popular posts from this blog

Day 32 - Python Script to track Available COVID-19 Vaccine Slots for 18+ in India

DAY 13 - Import data dynamically from Oracle DB using Python script in Power BI Desktop

DAY 31 - Organize a Secret Santa Game in your organization using a Python Script