# Python Assignment Operator

Assignment Operator

The assignment operator is used to assign a value to a variable.

Program
x = 5 #It will assign 5 to variable x print(x) #5 x+=1 #It will increment the value of x by 1 print(x) #6 x-=1 #It will decrement the value of x by 1 print(x) #5 x*=2 #It will multiply the value of x by 2 print(x) #10 x/=2 #It will divide the value of x by 2 print(x) #5.0 - It will give float value x = 5 #reassign value to x x%=2 #It will mod the value of x by 2 print(x) #remainder = 1 x = 5 #reassign value to x x//=2 #It will do floor division the value of x by 2 print(x) #2 - It will not give the float value x**=3 #It will do the value of x to the power of 3 print(x) #8 = 2 * 2 * 2 . Here x=2 from the previous iteration x&=3 #It will do bitwise & - And operation in between the value of x and 3 print(x) #8 & 3 = 1000 & 0011 = 0000 . Hence Result is 0 x = 8 #reassign value to x x|=3 #It will do bitwise | - Or operation in between the value of x and 3 print(x) #8 | 3 = 1000 | 0011 = 1011 . Hence Result is 11 x = 5 #reassign value to x x^=3 #It will do bitwise ^ - Xor operation in between the value of x and 3 print(x) #5 ^ 3 = 0101 ^ 0011 = 0110 . Hence Result is 6 x = 5 #reassign value to x x>>=1 #In this, all the bit are shifted to right, by pushing 0 from right. print(x) #5 = 0101 = 0010(shifted to right by 1) = 2 x = 5 #reassign value to x x<<=1 #In this, all the bits are shifted to the left, by pushing 0 from left. print(x) #5 = 0101 = 1010(shifted to left by 1) = 10
Input
Output

#### Similar Program

# Program Language
1 Python 3
2 Python 3
3 Python 3
4 Python 3
5 Python 3
6 Python 3
7 Python 3
8 Python 3
9 Python 3
10 Python 3
11 Python 3
12 Python 3
13 Python 3
14 Python 3
15 Python 3
16 Python 3
17 Python 3
18 Python 3
19 Python 3
20 Python 3
# Program Language