Skip to content

Augmented Assign

Sourcery refactoring id: aug-assign


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.