ASSIGNMENT TYPE OF OPERATORS


Assignment type Of Operators

Assign means to allocate. Assignment operators are used to assigning values to the variable or to perform operations. Assignment operators have special symbols for each function.
The variable is the operand, as the operator operates on the variable to assign the values.

There are many Assignment Operators in Python:-

  • Assign - The right-side value is assigned to the left side operand.
  • Add and Assign - Right side operand is added with the left side operand and then assign the final value to the left side operand.
  • Subtract and Assign - Right side operand is subtracted from the left side operand and then assign the final value to the left side operand.
  • Multiply and Assign - Right side operand is multiplied with the left side operand and then assign the final value to the left side operand.
  • Divide and Assign - It divides the left operand with the right value assigning the result to the left operand.
  • Modulus and Assign - It takes modulus using two values(operands) and assign the result to the left operand.
  • Divide (floor) and Assign - It performs floor division on operators and assigns value to the left variable.
  • Exponent and Assign - Performs exponential (power) calculation on operators and assigns value to the left variable.
  • Bitwise AND and Assign - Perform Bitwise AND operation on both operands and assign the result to the left operand.
  • Bitwise OR and Assign - Perform Bitwise OR operation on both operands and assign the result to the left operand.
  • Bitwise XOR and Assign - Perform Bitwise XOR operation on both operands and assign the result to the left operand.
  • Bitwise Right Shift and Assign - Perform Bitwise Right Shift operation on operands and assign the result to the left operand.
  • Bitwise Left Shift and Assign - Perform Bitwise Left Shift operation on operands and assign the result to the left operand.

Example:-

                =

  Assigns values from right side to left side.

  += Add

  It adds the right value to the left value and assigns the result to the left operand..

  -= Subtract

  It subtracts the right value from the left value and assigns the result to the left variable.

  *= Multiply

  It multiplies the right operand with the left value assigning the result to the left operand.

  /= Divide

  It divides the left operand with the right value assigning the result to the left operand.

  %= Modulus

  It takes modulus using two values(operands) and assign the result to the left operand.

  **= Exponent

  Performs exponential (power) calculation on operators and assigns value to the left variable.

  //= Floor Division

  It performs floor division on operators and assigns value to the left variable.

Example:

x = 5 print(x) x = 5 x |= 3 print(x) x = 5 x >>= 3 print(x) x = 5 x%=3 print(x) x = 5 x += 3 print(x)

OUTPUT:

5
7
0
2
8