Tuesday, 4 June 2019

Arithmetic Operators

Arithmetic operators:

Arithmetic operators perform basic arithmetic operations, for example, Addition, subtraction, multiplication, division, % modulus, exponent, etc.

Example:

For arithmetic operators, we will take a simple example of addition where we will add two-digit 4+5=9

Operator
Meaning
Example
Output
+
Addition
a=2+3
print(a): 5
-
Subtraction
a=4-2
print(a): 2
*
Multiplication
a=2*3
6
/
Division: divides left operand by the right operand
a=4/2
2
%
Modulus gives a remainder of division
4%2
0
//
Integer division. Floor division. Performs division and gives only integer quotient.
5//2
2
**
Exponent operator
10**2
100

Priorities of Arithmetic operators:

First priority: *,/,% and floor division are equal priorities.
2nd priority: +,-

Example:
a=2+3*2
-->Here the first '*' operator is evaluated i.e: 3*2 is evaluated i.e: a=2+6
-->Now '+' operator is evaluated i.e a=8
--->Now '=' assignment operator is evaluated i.e 8 is stored in variable 'a'


Youtube channel Related video
Next topic: Example programs on Arithmetic Operators
Previous topic: Operators

1 comment:

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(...