The following operations can be applied to all numeric types:

Operation | Description |
---|---|

x + y | Addition |

x - y | Subtraction |

x * y | Multiplication |

x / y | Division |

x // y | Truncating division |

x ** y | Power (x^{y}) |

x % y | Modulo (x
mod
y) |

–x | Unary minus |

+x | Unary plus |

The truncating division operator (also known as floor division) truncates the result to an integer and works with both integers and floating-point numbers. As of this writing, the true division operator (`/`) also truncates the result to an integer if the operands are integers. Therefore, `7/4` is `1`, not `1.75`. However, this behavior is scheduled to change in a future version of Python, so you will need to be careful. The modulo operator returns the remainder of the division `x // y`. For example, `7 % ...`

Start Free Trial

No credit card required