It is used to assign a value to a variable. Equal (=) is the assignment operator.
Operators |
Description |
= |
Assignment |
/= |
Divide and Assign |
+= |
Add and assign |
-= |
Subtract and Assign |
*= |
Multiply and assign |
%= |
Modulus and assign |
**= |
Exponent and assign |
//= |
Floor division and assign |
Example
Program:
a=10
a+=2
print("a+=2:",a)
a-=3
print("a-=3:",a)
a*=4
print("a*=2:",a)
a/=4
print("a/=4:",a)
a%=2
print("a%=2:",a)
a**=3
print("a**=3:",a)
a//=4
print("a//=4:",a)
Output:
a+=2: 12
a-=3: 9
a*=2: 36
a/=4: 9
a%=2: 1
a**=3: 1
a//=4: 0
Comments
Post a Comment