Assignment
operators are used to assign value to a variable. Following are the assignment
operators provided by python.
Operator
|
Description
|
=
|
a=10
assigns 10 to variable a
|
+=
|
a+=10 is
same as a=a+10
|
-=
|
a-=10 is
same as a=a-10
|
*=
|
a*=10 is
same as a=a*10
|
/=
|
a/=10 is
same as a=a/10
|
//=
|
a//=10 is
same as a=a//10
|
%=
|
a%=10 is
same as a=a%10
|
**=
|
a**=10 is
same as a=a**10
|
>>> a=10 >>> a 10 >>> >>> a+=10 >>> a 20 >>> >>> a-=10 >>> a 10 >>> >>> a*=10 >>> a 100 >>> >>> a/=10 >>> a 10.0 >>> >>> a//=10 >>> a 1.0 >>> >>> a**=10 >>> a 1.0
Multiple Assignments
You can assign values to multiple variables
simultaneously.
>>> a, b, c = 10, 'hello', 12.345 >>> a 10 >>> b 'hello' >>> c 12.345
No comments:
Post a Comment