The operator
module in Python provides a set of efficient functions corresponding to the intrinsic operators of Python. These functions are useful for simplifying and improving the readability of your code, especially when working with higher-order functions such as map()
, filter()
, and reduce()
. Below is a list of some commonly used functions in the operator
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python operator Module Tutorial.
Python operator Module Functions Table
Function | Description |
---|---|
operator.add() | Returns the sum of two numbers. |
operator.concat() | Concatenates two sequences. |
operator.contains() | Checks if an element is present in a container. |
operator.truediv() | Performs true division of two numbers. |
operator.floordiv() | Performs floor division of two numbers. |
operator.and_() | Performs bitwise AND operation. |
operator.xor() | Performs bitwise XOR operation. |
operator.invert() | Performs bitwise inversion. |
operator.or_() | Performs bitwise OR operation. |
operator.pow() | Returns the result of raising the first number to the power of the second number. |
operator.is_() | Checks if two objects are the same. |
operator.is_not() | Checks if two objects are not the same. |
operator.setitem() | Sets the value of an item in a container. |
operator.delitem() | Deletes an item from a container. |
operator.getitem() | Gets the value of an item in a container. |
operator.lshift() | Performs bitwise left shift operation. |
operator.mod() | Returns the remainder of division of two numbers. |
operator.mul() | Returns the product of two numbers. |
operator.neg() | Returns the negation of a number. |
operator.not_() | Returns the logical negation of a value. |
operator.pos() | Returns the value unchanged. |
operator.rshift() | Performs bitwise right shift operation. |
operator.iadd() | Performs in-place addition. |
operator.isub() | Performs in-place subtraction. |
operator.imul() | Performs in-place multiplication. |
operator.itruediv() | Performs in-place true division. |
operator.ifloordiv() | Performs in-place floor division. |
operator.imod() | Performs in-place modulus operation. |
operator.ipow() | Performs in-place exponentiation. |
operator.ilshift() | Performs in-place bitwise left shift. |
operator.irshift() | Performs in-place bitwise right shift. |
operator.iand() | Performs in-place bitwise AND operation. |
operator.ior() | Performs in-place bitwise OR operation. |
operator.ixor() | Performs in-place bitwise XOR operation. |
operator.abs() | Returns the absolute value of a number. |
operator.index() | Returns the integer value of an object. |
operator.attrgetter() | Returns a callable that fetches the given attribute from an object. |
operator.itemgetter() | Returns a callable that fetches the given item from an object. |
operator.methodcaller() | Returns a callable that calls the given method on an object. |
operator.countOf() | Returns the count of the number of times an element appears in a container. |
operator.indexOf() | Returns the index of the first occurrence of an element in a container. |
operator.truth() | Returns the truth value of an object. |
operator.lt() | Returns True if the first argument is less than the second. |
operator.le() | Returns True if the first argument is less than or equal to the second. |
operator.eq() | Returns True if the first argument is equal to the second. |
operator.ne() | Returns True if the first argument is not equal to the second. |
operator.ge() | Returns True if the first argument is greater than or equal to the second. |
operator.gt() | Returns True if the first argument is greater than the second. |
For more detailed information on each function, refer to the official Python documentation.