Operator Functions in Python
Python has predefined functions for several mathematical, logical, relational, bit wise etc operations under the module “operator”. a number of the essential functions are covered during this article.
- add (a, b) : This function returns additionof the given arguments.
Operation – a + b. - sub (a, b):This function returns difference of the given arguments.
Operation – a – b. - mul (a, b): This function returns productof the given arguments.
Operation – a * b
Output:
[pastacode lang=”python” manual=”The%20addition%20of%20numbers%20is%20%3A7%0AThe%20difference%20of%20numbers%20is%20%3A1%0AThe%20product%20of%20numbers%20is%20%3A12″ message=”” highlight=”” provider=”manual”/] 4. true div(a,b) :- This function returns division of the given arguments.
Operation – a / b.
5. floor div(a,b) :- This function also returns division of the given arguments. But the value is floored value i.e. returns greatest small integer.
Operation – a // b.
6. pow(a,b) :- This function returns exponentiation of the given arguments.
Operation – a ** b.
7. mod(a,b) :- This function returns modulus of the given arguments.
Operation – a % b.
Output:
[pastacode lang=”python” manual=”The%20true%20division%20of%20numbers%20is%20%3A%202.5%0AThe%20floor%20division%20of%20numbers%20is%20%3A%202%0AThe%20exponentiation%20of%20numbers%20is%20%3A%2025%0AThe%20modulus%20of%20numbers%20is%20%3A%201″ message=”” highlight=”” provider=”manual”/] 8. lt(a, b) :- This function is used to check if a is less than b or not. Returns true if a is less than b, else returns false.
Operation – a < b.
9. le(a, b) :- This function is used to check if a is less than or equal to b or not. Returns true if a is less than or equal to b, else returns false.
Operation – a <= b.
10. eq(a, b) :- This function is used to check if a is equal to b or not. Returns true if a is equal to b, else returns false.
Operation – a == b.
Output:
[pastacode lang=”python” manual=”3%20is%20not%20less%20than%203%0A3%20is%20less%20than%20or%20equal%20to%203%0A3%20is%20equal%20to%203″ message=”” highlight=”” provider=”manual”/] 11. gt(a,b) :- This function is used to check if a is greater than b or not. Returns true if a is greater than b, else returns false.
Operation – a > b.
12. ge(a,b) :- This function is used to check if a is greater than or equal to b or not. Returns true if a is greater than or equal to b, else returns false.
Operation – a >= b.
13. ne(a,b) :- This function is used to check if a is not equal to b or is equal. Returns true if a is not equal to b, else returns false.
Operation – a != b.




