F Anyone Can Code.
Assignment operators are used to assign values to a variable and can even perform certain operations during assignment. Given below are the major assignment operators.
Operator | Operation |
---|---|
= | x = x |
+= (y) | x = x + y |
-= (y) | x = x - y |
*= (y) |
x = x * y |
/= (y) | x = x / y |
//= (y) | x= x // y |
**= (y) | x = x ** y |
%= (y) | x = x % y |
#equal to x = 2 #equals to sum x += 18 print(x) #equals to difference x= 10 x -= 4 print(x) #equals to product x= 3 x *= 4 print(x) #equals to quotient x = 15 x /= 4 print(x) #equals to quotient (floor) x = 20 x //= 6 print(x) #equals to value raised to the power x= 8 x **= 3 print(x) #equals to remainder x = 14 x %= 4 print(x)
20 8 12 3.75 3 64 2
Here's a graphic for a quick recap:
That's it for this tutorial! Click Next to access the next tutorial!
This site uses cookies to improve your experience as well as for site metrics. To see more, check out our Privacy Policy