Skip to main content

Arithmetic Operators in Python

One of the very basic stuff in learning any programming language is learning operators. Here is a list and explanations of arithmetic operators in Python.



  1.  + :Add.
  2.  -:Subtract
  3.  *:Multiply
  4.  /: Divide
  5.  %: Modulus
    i.e. It calculates remainder. 7%3=1
  6.  //: Floor Division
    i.e. It is division after leaving the remainder. 29//5=5
    but, -29//5=-6
  7. **: Exponent(power)
    i.e. 3**4=81

Comments

Popular posts from this blog

Bitwise Operators in Python

The values are first converted into binary form, then operations are done, after that the result is converted back to decimal form and the result is displayed. So, it can be a little tricky to understand these operators, but with practice, anything can be understood. [ In python, if you want to see binary equivalent of an integer (say 45), use command bin(45) . But, if you want to see binary equivalent of 'blogger' use command  map ( bin , bytearray ('blogger' )) ] Bitwise operators in Python are: & (binary and): observe and understand:               a= 00010010               b= 10101010 then, a&b= 00000010    In your IDLE or wherever you type in your python commands try 15&12, 60&12, 13&15. [NOTE THAT: Python displays answers by converting it back to decimal form.] | (binary or): Also known as inclusive or.            a= 0001     ...

Assignment Operators in Python

These operators assign value to a variable after operation is done. Here is the list of such operators: = : Assigns the value of right side to left side. In a=b, the value of b is assigned to a. += (Add And) : a+=c is equivalent to a=a+c -= (Subtract And): a-=c is equivalent to a=a-c *= (Multiply And) /=(Divide and) %=(Modulo And) //= (Floor Division And) **=(Exponent And) If you don't know what modulo, floor division and exponent are, visit: Arithmetic Operators