Assignment Operators
Nerd Cafe
What Are Assignment Operators?
Step-by-Step Breakdown with Real Examples
1. Basic Assignment =
=x = 5
print(x)2. Add and Assign +=
+=x = 5
x += 3 # same as x = x + 3
print(x) # Output: 8loss = 0.0
loss += 0.25 # adding batch loss to total loss3. Subtract and Assign -=
-=4. Multiply and Assign *=
*=5. Divide and Assign /=
/=6. Modulus and Assign %= (Remainder)
%= (Remainder)7. Exponent and Assign **=
**=8. Floor Divide and Assign //=
//=Summary Table
Operator
Description
Example (x = 5)
Result (x)
Practical Machine Learning Example
Output:
Keywords
Last updated