syntax – What does the /= operator mean in Python?

syntax – What does the /= operator mean in Python?

Its an assignment operator shorthand for / and =.

Example:

x = 12
x /= 3
# equivalent to
x = x / 3

If you use help(/=), you can get the full amount of symbols supported by this style of syntax (including but not limited to +=, -=, and *=), which I would strongly encourage.

Its an augmented assignment operator for floating point division. Its equivalent to

x = x / 3

Per Makotas answer above, the following is provided by python 3, including the target types and operators, see https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements for more info:

augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)

augtarget ::= identifier | attributeref | subscription | slicing

augop ::= += | -= | *= | @= | /= | //= | %= | **=
| >>= | <<= | &= | ^= | |=

syntax – What does the /= operator mean in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *