Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Inplace operator in Python
Definition - In-place operation is an operation that changes directly the content of a given linear algebra, vector, matrices(Tensor) without making a copy. The operators which helps to do the operation is called in-place operator.
Eg: a+= b is equivalent to a= operator.iadd(a, b)
There are some operators are used for In-place operation.
iadd()
This function is used to assign the current value and add them. This operator does x+=y operation. In case of strings, numbers assigning is not performed.
Example
a =operator.iadd(1, 3);
print ("The result after adding : ", end="")
print(a)
Output
The result after adding: 5
isub()
This function is used to assign the current value and subtract them. This operator does x-=y operation. In case of strings, numbers assigning is not performed.
Example
a =operator.isub(8, 6);
print ("The result after subtracting : ", end="")
print(a)
Output
The result after subtracting: 2
imul()
This function is used to assign the current value and multiply them. This operator does x*=y operation. In case of strings, numbers assigning is not performed.
Example
a =operator.imul(8, 6);
print ("The result after multiplying : ", end="")
print(a)
Output
The result after multiplying: 48
itruediv()
This function is used to assign the current value and divide them. This operator does x/=y operation. In case of strings, numbers assigning is not performed.
Example
a =operator.itruediv(54, 6);
print ("The result after dividing : ", end="")
print(a)
Output
The result after dividing: 9
imod()
This function is used to assign the current value and divide them. This operator does x%=y operation. In case of strings, numbers assigning is not performed.
Example
a =operator.imod(10, 5);
print ("The result after modulus : ", end="")
print(a)
Output
The result after modulus: 2.0
iconcat()
This function is used to concatenate two strings.
Example
a= "jupyter"
b = "notebook"
t =operator.iconcat(a, b)
print (" After concatenation : ", end="")
print (t)
Output
After concatenation : jupyter notebook
