- Python Tutorial
- Python variables and types
- Python Arithmetic Operators
- Python Lists – basics: define, access, assign, delete, print, concatenate
- Python Lists – Negative Indexing, Slicing, Stepping, Comparing, Max and Min
- Comparison Operators
- Assignment Operator
- Python membership and identity operators
- Python strings
- Python escape characters
- Python string special operators
- Built-in string operations in Python
- Built-in string operations in Python -II
- String Formatting Operators
- Special string operators
- Conditions in Python
- Loops in Python
- Functions in Python
- Python Classes, Objects and OOP concepts
- Class inheritance
- Generators
- Regular Expressions in Python
- Regular Expressions in Python – II
- Comprehension Lists in Python
- Python functions with multiple arguments
- Exception Handling in Python
- Sets in Python

The equal to operator ‘=’ assigns the value of the right operand to the left operand. Have a look at the following piece of code, a and b are two variables having different values. However, when we say ‘a=b’ the value of b is assigned to a .

a = 10; b = 15; print ('a = 10 and b = 15') a = b print ('if a = b then the value of "a" will change to:') print (a)

Download the code Run the code

The ‘+=’ operator is also known as Add AND operator. It adds the values of the left and the right operands and assigns the result to the left operand. In the following example a+= b is same as a=a+b.

a = 10; b = 15; print ('a = 10 and b = 15') a += b print ('if a += b then the value of "a" will change to:') print (a)

Download the code Run the code

The ‘-=’ operator is also known as Subtract AND operator. It subtracts the value of the right operand from the value of the left operand and assigns the result to the left operand.Have a look at the following example a-=b is same as a=a-b.

a = 10; b = 15; print ('a = 10 and b = 15') a -= b print ('if a -= b then the value of "a" will change to:') print (a)

Download the code Run the code

The ‘*=’ operator is also known as Multiply AND operator. It multiplies the value of the right and the left operand and assigns the result to the left operand. In the following example a*=b is same as a=a*b.

a = 10; b = 15; print ('a = 10 and b = 15') a *= b print ('if a *= b then the value of "a" will change to:') print (a)

Download the code Run the code

The Divide AND operator – ‘/=’ operator with divide the value of the left operand with the value of the right operand and will assign the result to the left operand. In the following example a/=b is same as a=a/b.

a = 10; b = 2; print('a = 10 and b = 2') a /= b print ('if a/=b then the value of "a" will change to:') print (a)

Download the code Run the code

The Modulus AND operator – ‘%=’ operator with divide the value of the left operand with the value of the right operand and will assign value of the modulus to the left operand. In the following example a%=b is same as a= a%b.

a = 10; b = 2; print ('a = 10 and b = 2') a %= b print ('if a %= b then the value of "a" will change to:') print (a)

Download the code Run the code

‘**=’ operator is also known as the exponent AND operator. It finds the value of the left operand raised to the power of the right operand and then assign the result to the left operand. In the following example a**=b is same as a= a raised to the power of b.

a = 10; b = 2; print ('a = 10 and b = 2') a **= b print ('if a **= b then the value of "a" will change to:') print (a)

Download the code Run the code

‘//=’ operator is also known as the Floor division AND operator. It will perform the floor division between the two values and assign the result to the left operand. In the following example a//=b is same as a = a//b.

a = 10; b = 2; print ('a = 10 and b = 2') a //= b print ('if a//=b then the value of "a" will change to:') print (a)