لَآ إِلَـٰهَ إِلَّا هُوَ
LA ILAHA ILLA HU
Allah, Your Lord There Is No Deity Except Him.

Lesson 15: Assignment Operators in Python

Assignment Operators In Python are used to assign values to variables.

Operator Example Same As
= x = 5 x = 5
+= x += 5 x = x + 5
-= x -= 5 x = x - 5
*= x *= 5 x = x * 5
/= x /= 5 x = x / 5
%= x %= 5 x = x % 5
//= x //= 5 x = x // 5
**= x **= 5 x = x ** 5
&= x &= 5 x = x & 5
|= x |= 5 x = x | 5
^= x ^= 5 x = x ^ 5
>>= x >>= 5 x = x >> 5
<<= x <<= 5 x = x <<= 5

Explanation

&

& pronounced as 'AND' Sets each bit to 1 if both bits are 1.

|

| pronounced as 'OR'Sets each bit to 1 if one of two bits is 1.

^

^ pronounced as 'XOR'(exclusive OR) is also known as a 'caret operator (^)' Sets each bit to 1 if only one of two bits is 1.

~

~ it means 'NOT Inverts all the bits.

<<

<< is known as 'Zero fill left 'shift' Shift left by pushing zeros in from the right and let the leftmost bits fall off.

>>

>> is known as 'Signed right shift' Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off.