How to Divide in Python?

Use `/` for true division

Use `//` for floor division

Use `%` to get the remainder

Use `divmod(a, b)` to get quotient and remainder

Use `int(a / b)` to truncate toward zero

Use `fractions.Fraction(a, b)` for exact rational division

Use `decimal.Decimal` for precise decimal division

Handle division by zero with `try` and `except ZeroDivisionError`

Suggested for You

Trending Today