Python supports unique symbols that perform basic arithmetic and logical calculations. In this shot, we’ll be discussing some of the basic arithmetic operators used in Python.
+
operatorJust like basic mathematics, the +
sign in Python is used to add two variables together. If you want to add two variables, all you have to do is write variable 1, followed by the +
operator, and then variable 2.
var1=2var2=4print (var1 + var2)
-
operatorThe -
operator can be used to subtract two variables. In order to subtract two variables, just write variable 1, followed by the -
operator, then variable 2.
var1=8var2=4print (var1 - var2)
*
operatorIn Python, you can use the *
operator to easily multiply two variables.
var1= 4var2= 4print(var1 * var2)
/
operatorUse the /
operator to divide variable 1 by variable 2.
var1= 16var2= 4print(var1 / var2)