This article all about the arithmetic operators and their operation in python the following tables and coding shows some examples of how to use the arithmetic operators in python.
PYTHON ARITHMETIC OPERATORS
Arithmetic operations are the mathematical function which is used to perform functions like Addition, Subtraction, Multiplication, and Division.
Table to show operations and operators
Operation

operation

Syntax for operation

+

Addition of two
operands

a+b , 8+9
, 8+2



Subtracts two operands

ab , 89 ,82

*

Multiplication of two
operands

a*b, 32*5

/

Division of two operands /Float(ans)

a/b
,32/4

//

Davison of two
operands/int(ans)

x//y , 33/4 , 10/3

%

Modulus or shows the remainder

10%3

**

For giving the power
to the number

2**3 means 2^{3}

Addition operator examples in python(+)
Remember that >>> this is the inputs given by the user and blank space below this is the computergenerated answer or output
>>> 2+3 here we just added two number then press enter
5 then we get the output
>>> a=5 we assign variable "a" as 5
>>> b=6 variable "b" as 6
>>> a+b= and here we added this variables
11 wow we get the asnwer as integer after pressing enter.
>>> a+b+11 here we already assign the value of "a,b" and added an integer number to it that is 11.
22 we get the result as 22 because "a=5, b=6" we already define this variable
>>> 132+145+a+b here we have added two big numbers with our already assign values number then we get the desired result.
288
As you can see the python has very userfriendly coding system which can be used by anyone quite easily this codes come from IDLE of python3 so hope you will enjoy the later part of this blog where all the operations are used in quite complex equation which can help you to understand the all python arithmetic operators.
Subtract Operators in python()
>>> 35445
309
>>> 264245
19
>>> x=6
>>> y=9
>>> x+y
15
>>> x+y10
5
Multiplication Operators in python()
Multiplication operator is also very easy as you just have to put * for multiplication of two numbers.
>>> 14*2
28
>>> 14*36
504
>>> x*y
54
Division Operators in python(/)
This is a very important operator in python you need to understand the difference between integer number and float number.
Integer Numbers : 1 , 2 , 3,4,5,6,7,8,9,10..
Float Number: 12.00, 11.36 , 14.29 , 11.78 ,19.37..
>>> 14/2
7.0
>>> 1123/135 When we use the / operator we are dividing the number and answer is coming with the decimal point
8.318518518518518
>>> 112/4
28.0
>>> 126/48
2.625 this answer can be written as 2 + 0.625 that 0.625 is the decimal value and by using / we are getting the decimal answer sometimes it may be whole number 7.0 but it still shows .0 that means it is showing the integral value.
Division Operators in python for INTEGER VALUE(//)
In the above example, you have seen the result is coming in decimal form like if we divide 10 with 3 we will get the answer as 3.33 and but what if someone wants to divide the number but didn't want the answer in a decimal form then he can use the // operator lets see the example
>>> 10/3 By using single divisional operator
3.3333333333333335 float
>>> 10//3 By using double divisional operator
3 integer
Modulus Operators in python (%)
Modulus operator is used to determine the remainder for example if you divide 10 by 3 then you will get the remainder 1 as 10 cannot be divided by 3 with zero remainder so if we have to find the remainder we will use the Modulus operator.let's see the programme and understand that.
>>> 10%3
1
>>> 1235%23
16
>>> 4523%13
12
Exponential or power Operators in python (**)
Suppose I have to write the programme where I have to write the square , cube or 10th to the power n of any number then we can use this operator lets see this in example
>>> 2*2*2*2 Here you can see the 2 is multiplied by 4 times if I want to do that for 100 the time it will be tough to write the multiplication to reduce that effort we are using **
16
>>> 2**4 This Statement means 2 to the power 4 as you can see both results are same
16
thank you for reading if you like my blog please do mention that in the comment section below and do share with your friends and enjoy learning
this is all about the python arithmetic operators.
Nice info really loved reading your blog I also found your posts very interesting.in fact after reading ,I had to go show it to my friends and enjoyed it as well . Free Multiplication Games
ReplyDelete