Python Assignment operators
Assignment operators are used to assign values to variables. In Python Arithmetic as well as Bitwise operators can be combined with assignment operator, for updating variables.
Makes it easier for users to update and assign the values to variables.
'=' is the basic assignment operator.
Operator | Operation |
---|---|
= | Is equal to(assign) |
+= | Add and assign |
-= | Subtract and assign |
*= | Multiply and assign |
/= | Divide and assign |
%= | Modulus and assign |
**= | Exponentiate and assign |
//= | Floor Division and assign |
&= | Bitwise AND and assign |
|= | Bitwise OR and assign |
^= | Bitwise XOR and assign |
<<= | Zero fill LEFT SHIFT and assign |
>>= | Zero fill RIGHT SHIFT and assign |
Assignment operators makes the things easier and shorter.
Assignment operator
An assignment operator is 'is equal to' operator which we use in mathematics, for assigning values.
Assignment operators are basically used in initialization of variables.
Program
First and foremost, the variables are initialized and then they are updated by using the following assignment operators.
Python Add and assign operator
Once variables are initialized they can be updated by adding it with a value, and then it gets assign to the updated value. This can be done by using add and assign operator.
First the variable gets updated and then it is assign with the updated value.
Program
Python Subtract and assign operator
Once variables are initialized they can be updated by subtracting it with some value, and then the variable gets assigned with the updated value. This can be done by using Subtract and assign operator.
Program
Python Multiply and assign operator
Once variables are initialized they can be updated by multiplying it with a value, and then it gets assign with the variable. This can be done by using multiply and assign operator.
Program
Python Divide and assign operator
Once variables are initialized they can be updated by dividing it with a value, and then the updated value gets assign with the variable. This can be done by using divide and assign operator.
Program
Python Modulus and assign operator
Getting the modulus and then assigning it with the variable. This can be done by using modulus and assign operator.
Program
Python Exponentiate and assign operator
Exponentiation operation is done and then the result is assigned to the variable. This can be done by using exponentiate and assign operator.
Program
Python Floor division and assign operator
Firstly the Floor division is performed and then the updated value is assigned to the variable. This can be done by using Floor division and assign operator.
Program
Python Bitwise AND and assign operator
Performing Bitwise AND operation and then assigning the updated value to the variable. This can be done by using Bitwise AND and assign operator.
Program
Python Bitwise OR and assign operator
OR operation is performed first and then the updated value is assigned to the variable. This can be done by using Bitwise OR and assign operator.
Program
Python Bitwise XOR and assign operator
XOR operation is performed first and then the updated value is assigned to the variable. This can be done by using Bitwise XOR and assign operator.
Program
Python Zero fill LEFT SHIFT and assign operator
Bitwise 0 fill LEFT SHIFT operation is done first and then the updated value is assigned to the variable. This can be done by using Bitwise zero fill LEFT SHIFT and assign operator.
Program
Python Zero fill RIGHT SHIFT and assign operator
Bitwise 0 fill RIGHT SHIFT operation is done first and then the updated value is assigned to the variable. This can be done by using Bitwise zero fill RIGHT SHIFT and assign operator.
Program
Post a Comment
If you have any query, feel free to ask.