Skip to content

Augmented Assign

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.

Replaces assignments with augmented assignments

count = count + other_value
count += other_value

Reading the changed code is a bit shorter and clearer - we don’t need to think about the count variable twice. Other operators that can be used include -=, *=, /= and **=.

The type you’re assigning to has to have the appropriate operator defined, so Sourcery will only suggestion this change where it can determine the type and it is suitable. For instance numpy arrays do not support the /= operation.