The `operator` module provides functions that access the built-in operators and special methods of the interpreter described in Chapter 3. For example, `add(3, 4)` is the same as `3 + 4`. When the name of a function matches the name of a special method, it can also be invoked using its name with double underscores—for example, `__add__(3, 4)`.

Function | Description |
---|---|

add(a, b) | Returns a + b for numbers |

sub(a ,b) | Returns a – b |

mul(a, b) | Returns a* b for numbers |

div(a, b) | Returns a / b(old division) |

floordiv(a, b) | Returns a // b |

truediv(a ,b) | Returns a / b(new division) |

mod(a, b) | Returns a % b |

neg(a) | Returns -a |

pos(a) | Returns +a |

abs(a) | Returns the absolute value of a |

inv(a), invert(a) | Returns the inverse of a(~a) |

lshift(a, b) | Returns a << b |

rshift(a, b) | Returns a >> b |

and_(a, ... |

Start Free Trial

No credit card required