assignment operators


Introduction
These are assignment operators in Python and their operation depends on their functions.Python have number of very nicely defined operator to make the programming more concise and control to reduce the programming complications. 
  • = implies x=y
  • += implies x=x+y
  • -= implies x=x-y
  • *= implies x=x*y
  • /= implies x=x/y
  • **= implies x=x**y
  • //= implies x=/y*y

Examples
a+=b
In this first example, the python add the value of the x to existing value of y and come up with 58 value.
 >>> 
>>> b=3
>>> b+=55
>>> 
>>> b
58

a-b
In this assignment operator, the python calculated the value by x-y.
 >>> a=4
>>> a-=5
>>> a
-1

a*=b
The multiplication function is performed to variable which returns with the value 99.
 >>> 
>>> a=9
>>> a *=11
>>> a
99


a/=b
Division function is also operated in similar function. 
 >>> 
>>> a=6
>>> a/=6
>>> 
>>> a
1.0

Tuple
The tuple value are assigned in to variable.
 >>> 
>>> (x,y,z)=("python", "Lake", "Learning")
>>> print(x)
python
>>> print(y)
Lake
>>> print(z)
Learning


The tuple value are assigned in to variable.
 >>> 
>>> (x,y,z)=("python", "Lake", "Learning")
>>> print(x)
python
>>> print(y)
Lake
>>> print(z)
Learning

Comments