Every business requirement, you will convert in the code will require some operation; it could be a mathematical operation, logical operation, etc. Mathematical operations mean addition, subtraction, division, multiplication or any other combination of mathematical operations. The logical operation means either this or that; these can be implemented using relational operators and logical operators.

Before getting into specific details of operators let us have a look at a statement and understand what all components are present in a statement.

b+c

In this statement, "b" and "c" are operands, and "+" is the operator. Every operator has two operands.

Whatever arithmetical operation you can think of is present in Python, whether it is basic BODMAS operations or power or percentage operations

Operator | Operation | Description | Example |
---|---|---|---|

+ | Addition | Sum the value of both operands on either side of "+" operator | x+y gives 13 |

- | Subtraction | Subtract the value of right operands from left side operands | x-y gives 7 |

/ | Division | Divide the left side operand by right side operand | x/y gives 3 |

* | Multiplication | Multiply the left side operand by right side operand | x*y gives 30 |

% | Modulus | Gives the remainder after dividing the left side operand by right side operand | x%y gives 1 |

** | Exponent | return value of left operand to the power of right operand | x**y gives 1000 |

// | Floor Division | Gives the rounded off quotient towards negative infinity after dividing the left side operand by right side operand | x//y gives 3 |

In Assignment operator, Python gives you the facility to use less keystroke to perform arithmetic operation and almost every programming language support this kind of assignment operator

Operator | Operation | Description | Example |
---|---|---|---|

= | Basis assignment | Assign the value of right operand to left operand | x=3 assignes 3 to x |

+= | Addition assignment | Assign the sum of Left and the Right operand to left operand | x+=y assigns x with 13 ≈ x=x+y |

-= | Subtraction assignment | Subtract the value of right operand from left operand and assign it to left operand | x-=y assigns x with 7 ≈ x=x-y |

/= | Division assignment | divide the value of left operand with right operand and assign the quotient to left operand | x/=y assigns x with 3 ≈ x=x/y |

*= | Multiplication assignment | Multiplies the value of left operand with right operand and assign the multiplication to left operand | x/=y assigns x with 30 ≈ x=x*y |

%= | Modulus assignment | Divides the value of left operand from right operand and assigns the remainder to left operand | x%=y assigns x with 1 ≈ x=x%y |

**= | Exponent assignment | calculate the value of left operand to the power right operand and assign the result to left operand | x**=y assigns x with 1000 ≈ x=x**y |

//= | Floor Division | assignment divide the value of left operand from right operand and assign the rounded off quotient towards negative infinity to left operand | x//=y assigns x with 3 ≈ x=x//y |

Python provides you the functionality to handle relation kind of operation e.g. a is larger than b or b is smaller than a.

Operator | Operation | Description | Example |
---|---|---|---|

> | greater than | Return true if the left operand is greater than the right operand | x > y gives true |

< | less than | Return true if the left operand is lesser than the right operand | x < y gives false |

>= | greater than equal to | Return true if the left operand is greater than or equal to the right operand | x >= y gives true |

<= | less than equal to | Return true if the left operand is lesser than or equal to the right operand | x <= y gives false |

== | equal to | Return true if the left operand is equal to the right operand | x == y gives false |

!= | not equal to | Return true if the left operand is not equal to the right operand | x != y gives true |

In all above example assume x=10 and y=3

Before moving further practice these operators as much as you can to increase the understanding with these. Apart from these operators, Python has logical operators, bitwise operators which we will see in the next article.