DEV Community

loading...
Cover image for Arithmetic operators in python

Arithmetic operators in python

aswin2001barath profile image Aswin Barath Updated on ・1 min read

Operators are used to performing operations on any given data stored inside variables.

And arithmetic operators makes mathematical operations possible on operands in a program.

I know! I know! This is a basic concept! But let's make it fun!

Starting with addition and subtraction

Alt Text
Output:

Addition 9
Subtraction 8
Enter fullscreen mode Exit fullscreen mode

Now, Multiplication and Division

Alt Text
Output:

Multiplication 314.0
Division 2.0
Enter fullscreen mode Exit fullscreen mode

Special arithmetic operators

  • Floor division - //: rounds of the result to the nearest whole number.
  • Modulus - %: produces the remainder of the numbers Alt Text Output:
Floor Division 3
Modulus 1
Enter fullscreen mode Exit fullscreen mode
  • Exponentiation - ** : produces the power of given numbers Alt Text Output:
Exponentiation 0.025517964452291125
Exponentiation 37.78343433288728
Enter fullscreen mode Exit fullscreen mode

Code along and have fun ;)

Discussion (0)

Forem Open with the Forem app