0% found this document useful (0 votes)
2 views1 page

15.operators in Python-Assignment Operators

The document explains assignment operators in Python, which store values from the right side into variables on the left side and can perform arithmetic operations. It provides examples of various assignment operators such as +=, -=, *=, and /=, along with their results when applied to specific variable values. Additionally, it mentions that Python does not support increment (++) and decrement (--) operators found in other programming languages like C and Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

15.operators in Python-Assignment Operators

The document explains assignment operators in Python, which store values from the right side into variables on the left side and can perform arithmetic operations. It provides examples of various assignment operators such as +=, -=, *=, and /=, along with their results when applied to specific variable values. Additionally, it mentions that Python does not support increment (++) and decrement (--) operators found in other programming languages like C and Java.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assignment Operators

These operators are useful to store the right side value into a left side variable.
They can also be used to perform simple arithmetic operations like addition, subtraction,
etc., and then store the result into a variable.

In the Table below, let’s assume the values x = 20, y = 10 and z = 5:

Assignment Operators

Operator Example Meaning Result


Assignment operator. Stores right side value into left
= z = x+y z = 30
side variable, i.e. x+y is stored into z.
Addition assignment operator. Adds right operand to
+= z+=x the left operand and stores the result into left operand, z = 25
i.e. z = z+x.
Subtraction assignment operator. Subtracts right
-= z-=x operand from left operand and stores the result into z = -15
left operand, i.e. z = z-x.
Multiplication assignment operator. Multiplies right
*= z*=x operand with left operand and stores the result into left z = 100
operand, i.e. z = z *x.
Division assignment operator. Divides left operand with
/= z/=x right operand and stores the result into left operand, z = 0.5
i.e. z = z/x.
Modulus assignment operator. Divides left operand
%= z%=x with right operand and stores the remainder into left z=5
operand, i.e. z = z%x.
Exponentiation assignment operator. Performs power
**= z**=y value and then stores the result into left operand, i.e. z z= 9765625
= z**y.
Floor division assignment operator. Performs floor
//= z//=y division and then stores the result into left operand, z=0
i.e. z = z// y.

It is possible to assign the same value to two variables in the same statement as:

a=b=1
print(a, b) # will display 1 1

Another example is where we can assign different values to two variables as:
a=1; b=2
print(a, b) # will display 1 2

The same can be done using the following statement:


a, b = 1, 2
print(a, b) # will display 1 2

Python does not have increment operator ( ++ ) and decrement operator ( -- ) that are
available in C and Java.

You might also like