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”Description:
Section titled “Description:”Use Python’s built-in feature for succinct division syntax.
Before:
Section titled “Before:”result = int(42 / 10)After:
Section titled “After:”result = 42 // 10Before:
Section titled “Before:”result = 42 // 10remainder = 42 % 10After:
Section titled “After:”result, remainder = divmod(42, 10)Explanation:
Section titled “Explanation:”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.