Skip to content

Simplify Division

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: simplify-division

Section titled “Sourcery refactoring id: simplify-division”

Use Python’s built-in feature for succinct division syntax.

result = int(42 / 10)
result = 42 // 10
result = 42 // 10
remainder = 42 % 10
result, remainder = divmod(42, 10)

Python has some great features to simplify division expressions. If you’re interested only in the whole number component of the quotient, you can use the // integer division operator. If you want to have the whole number component and the remainder in separate variables, the built-in divmod function comes handy.