Assignment Operators in Python
Learn about Assignment Operators in Python.
Now that you know about arithmetic operators in Python, let's talk about another operator: the assignment operator.
It's actually nothing new to you. The assignment operator is the one used to assign a value to a variable:
But, you can combine arithmetic operators with the assignment operator. Let's see how this works
Here, the combination of +
and =
adds 8 to the already existing value of num.
You can combine the assignment operator =
with all arithmetic operators that you already now.
The subtraction operator turns into the minus-equal operator:
The multiplication operator turns into the multiply-equal operator:
The division operator turns into the divide-equal operator:
The exponential operator turns into the power-equal operator:
The floor division operator turns into the floor-divide-equal operator:
And last but not least the modulo operator turns into the modulo-equal operator: