/    /  Python – Operators

Python – Operators:

Operators in Python helps us to perform the mathematical operations with numbers. There are different operators in Python as below.

OperatorsDescription
//Integerdivision
+addition
subtraction
*multiplication
/Float division
%Provide remainder after division(Modulus)
**Perform exponent (raise to power)

Let us try implementing every operator now.

  1. Addition: symbol used (+)
>>> 10+10

20

>>>20+30

50

>>>50+50

100
  1. Substration: symbol used (-)
>>>20-10

10

>>>50-40

10

>>>100-30

70
  1. multiplication: Symbol used (*)
>>>5*2

10

>>>10*2

20

>>>20*2

40
  1. Float Division: This will divide and provide the result in floating value and the symbol used (/)
>>>5/2

2.5

>>>10/2

5.0
  1. Integer Division: This will divide and truncate the decimal and provide the Integer value and the symbol used (//)
>>>5//2

2

>>>7//2

3
  1. Exponentiation Operator: This will help us to calculate a power b and return the result
>>>10**3 # This mean 10*10*10

1000
  1. Modulus Operator: This will provide the remainder after the calucation and symbol used (%)
>>>10%3

1

What if we want to work with multiple operators at a time. Here comes the Operator precedence in Python.

OperatorDescription
lambdaLambda expression
if – elseConditional expression
orBoolean OR
andBoolean AND
not xBoolean NOT
in, not in, is, is not, <, <=, >, >=, !=, ==Comparisons, including membership tests and identity tests
|Bitwise OR
^Bitwise XOR
&Bitwise AND
<<, >>Shifts
+, –Addition and subtraction
*, @, /, //, %Multiplication, matrix multiplication division, remainder [5]
+x, -x, ~xPositive, negative, bitwise NOT
**Exponentiation [6]
await xAwait expression
x[index], x[index:index], x(arguments…), x.attributeSubscription, slicing, call, attribute reference
(expressions…), [expressions…], {key: value…}, {expressions…}Binding or tuple display, list display, dictionary display, set display