Assignment Operator

Assignment operators are used to assign values to variables. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value.a = 5 is a simple assignment operator that assigns the value 5 on the right to the variable a on the left.

OperatorDescriptionExample
=Assigns values from right side operands to left side operandc = a + b
+=It adds right operand to the left operand and assign the result to left operandc += a
-=It subtracts right operand from the left operand and assign the result to left operand-= a
*=It multiplies right operand with the left operand and assign the result to left operandc *= a
/=It divides left operand with the right operand and assign the result to left operandc /= a
%=It takes modulus using two operands and assign the result to left operandc %= a
**=Performs exponential (power) calculation on operators and assign value to the left operandc **= a
//=It performs floor division on operators and assign value to the left operandc //= a

Assignment Operator - Program Link

# Python Assignment Operator
a=int(input())
b=int(input())
a+=b
print(a)
a-=b
print(a)
a*=b
print(a)
a/=b
print(a)
a//=b
print(a)
a**=b
print(a)
Output:
4
2
4
2.0
1.0
1.0

References

  • Allen B. Downey, “Think Python: How to Think Like a Computer Scientist‘‘, 2nd edition, Updated for Python 3, Shroff/O‘Reilly Publishers, 2016 (http://greenteapress.com/wp/thinkpython/)
  • Guido van Rossum and Fred L. Drake Jr, ―An Introduction to Python – Revised and updated for Python 3.2, Network Theory Ltd., 2011.
  • John V Guttag, ―Introduction to Computation and Programming Using Python‘‘, Revised and expanded Edition, MIT Press , 2013
  • Robert Sedgewick, Kevin Wayne, Robert Dondero, ―Introduction to Programming in Python: An Inter-disciplinary Approach, Pearson India Education Services Pvt. Ltd., 2016.
  • Timothy A. Budd, ―Exploring Python‖, Mc-Graw Hill Education (India) Private Ltd.,, 2015. 4. Kenneth A. Lambert, ―Fundamentals of Python: First Programs‖, CENGAGE Learning, 2012.
  • Charles Dierbach, ―Introduction to Computer Science using Python: A Computational Problem-Solving Focus, Wiley India Edition, 2013.
  • Paul Gries, Jennifer Campbell and Jason Montojo, ―Practical Programming: An Introduction to Computer Science using Python 3‖, Second edition, Pragmatic Programmers, LLC, 2013.