
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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
- Related Articles
- Inplace vs Standard Operators in Python
- Inplace Operators in Python - iadd(), isub(), iconcat()
- Inplace Operators in Python - ixor(), iand(), ipow()
- Python Inplace Operators - iadd(), isub(), iconcat()
- Ternary Operator in Python?
- Operator Functions in Python
- What is @ operator in Python?
- Types of Operator in Python
- String Formatting Operator in Python
- What is operator binding in Python?
- Explain function of % operator in Python.
- What is tilde (~) operator in Python?
- What is modulo % operator in Python?
- What is "not in" operator in Python?
- What does the &= operator do in Python?
