Arithmetic operators in Python

 

Operators in Python

The Operators which are used in Python to perform a specific operation. From my opinion I love to work with Python operators and libraries, as they are very simple and easy to understand.


What are operators? 

An operator is a symbol that represents an operation to be performed on an operands. 


Example:- 30 + 5 = 35
Here '30' and '5' are operands and '+'  is an operator. 

This operator ('+')  represents add operation to be performed on 30 and 5 to give 35 as a result 


Basic operators in programming

Arithmetic operators in Python

These are all the common mathematical operators.


Here is an overview of arithmetic operators.

OperatorOperation
+Addition
-Subtraction
*Multiplication
/Division
%Modulus
**Exponentiation
//Floor division

Addition operator

Perform addition of two numbers.


Program

>>> 5 + 6
11
>>> a = 5
>>> b = 6
>>> c = a + b
>>> print(c)
11


Subtraction operator

Perform Subtraction of two numbers.


Program

>>> 6-5
1
>>> a = 5
>>> b = 6
>>> c = b-a
>>> print(c)
1


Multiplication operator

Multiply two numbers given to it.


Program

>>> 6*5
30
>>> a = 5
>>> b = 6
>>> c = b*a
>>> print(c)
30


Division operator

Divides the numbers given to it.


Program

>>> 6/2
3.0
>>> a = 6
>>> b = 2
>>> c = a/b
>>> print(c)
3.0


Modulus operator

Gives the remainder of division operation.


Program

>>> 10%6
4
>>> 6%10
6
>>> a = 6
>>> b = 10
>>> c = a % b
>>> print(c)
6


Exponentiation operator

Raising a number to the power of another number. double asterisks are used to denote exponentiation operation in Python.


Program 

>>> 2**3
8
>>> a = 2
>>> b = 3
>>> c = a**b
>>> print(c)
8


Floor division 

Rounds of the result got from division operation, down to the nearest whole number.


Program 

>>> 10//3
3
>>> a = 10
>>> b = 3
>>> c = a//b
>>> print(c)
3





Conclusion

Arithmetic operators are all the common mathematical operators.
In which we have learned addition, subtraction, multiplication, division, exponential and floor division.





Previous              Next

If you have any query, feel free to ask.

إرسال تعليق

If you have any query, feel free to ask.

Post a Comment (0)