Arithmetic Operators in Python
Arithmetic Operators in Python
Arithmetic operators are used with numeric values to perform common mathematical operations
Follows -
- Addition ( +) = x+y
- Subtraction ( - ) = x-y
- Multiplication ( * ) = x*y
- Division ( / ) = x/y
- Modulus ( % ) = x%y (Return remainder)
- Exponentiation ( ** ) = x**y (Return x^y)
- Floor Division ( // ) = x//y (Return quotient in integer )
So, let's see an example -
Code on Pydroid 3
Arithmetic Operators ?
x = 5
y = 2
- Addition (+) - This operator will return the sum of two or more operands. Second use of this operator is to join strings (string concatenation ).
Ex - print ( x+y )
Output = 7
Ex - x="Pyth"
y="on"
print ( x+y )
Output - Python
- Subtraction ( - ) - This is another arithmetic operator use to subtract two or more operands.
Example - print ( x-y )
Output - 3
- Multiplication ( * ) - This operator used for multiplication of operands. Another use for replication of strings.
Example - print ( x*y )
Output - 10
Example - x= "Py"
print (x*3)
Output - PyPyPy
- Division ( / ) - Used for division of two operands.
Example - print ( x/y )
Output - 2.5
- Modulus ( % ) - This is also come under arithmetic operator. It will return remainder of division.
Example - print ( x%y )
Output - 1 (remainder)
- Exponentiation ( ** ) - This will return x^y ( x to the power y).
Example - print ( x**y )
Output - 25
- Floor Division ( // ) - It will return the quotient value but only integer part ( no decimal ).
Example - print ( x//y)
Output - 2
Output of Question
All arithmetic operators are easy, only mathematical operations.
TASK OF THE DAY
You should always see the constraints. We have to do simple arithmetic operations.
- Addition
- Subtraction
- Multiplication
Solution
Comments
Post a Comment