Inplace Operators in Python | Set 2 (ixor(), iand(), ipow(),…)
Last Updated :
15 Jul, 2022
Inplace Operators in Python | Set 1(iadd(), isub(), iconcat()…)
More functions are discussed in this articles.
1. ixor() :- This function is used to
assign and xor the current value. This operation does "
a^ = b" operation. Assigning is
not performed in case of immutable containers, such as strings, numbers and tuples.
2. ipow() :- This function is used to
assign and exponentiate the current value. This operation does "
a ** = b" operation. Assigning is
not performed in case of immutable containers, such as strings, numbers and tuples.
Python
# Python code to demonstrate the working of
# ixor() and ipow()
# importing operator to handle operator operations
import operator
# using ixor() to exclusive or and assign value
x = operator.ixor(10,5);
# printing the modified value
print ("The value after xoring and assigning : ",end="")
print (x)
# using ipow() to exponentiate and assign value
x = operator.ipow(5,4);
# printing the modified value
print ("The value after exponentiating and assigning : ",end="")
print (x)
Output:
The value after xoring and assigning : 15
The value after exponentiating and assigning : 625
3. iand() :- This function is used to
assign and bitwise and the current value. This operation does "
a &= b" operation. Assigning is
not performed in case of immutable containers, such as strings, numbers and tuples.
4. ior() :- This function is used to
assign and bitwise or the current value. This operation does "
a |=b " operation. Assigning is
not performed in case of immutable containers, such as strings, numbers and tuples.
Python
# Python code to demonstrate the working of
# ior() and iand()
# importing operator to handle operator operations
import operator
# using ior() to or, and assign value
x = operator.ior(10,5);
# printing the modified value
print ("The value after bitwise or, and assigning : ",end="")
print (x)
# using iand() to and, and assign value
x = operator.iand(5,4);
# printing the modified value
print ("The value after bitwise and, and assigning : ",end="")
print (x)
Output:
The value after bitwise or, and assigning : 15
The value after bitwise and, and assigning : 4
5. ilshift() :- This function is used to
assign and bitwise leftshift the current value by second argument. This operation does "
a <<=b " operation. Assigning is
not performed in case of immutable containers, such as strings, numbers and tuples.
6. irshift() :- This function is used to
assign and bitwise rightshift the current value by second argument. This operation does "
a >>=b " operation. Assigning is
not performed in case of immutable containers, such as strings, numbers and tuples.
Python
# Python code to demonstrate the working of
# ilshift() and irshift()
# importing operator to handle operator operations
import operator
# using ilshift() to bitwise left shift and assign value
x = operator.ilshift(8,2);
# printing the modified value
print ("The value after bitwise left shift and assigning : ",end="")
print (x)
# using irshift() to bitwise right shift and assign value
x = operator.irshift(8,2);
# printing the modified value
print ("The value after bitwise right shift and assigning : ",end="")
print (x)
Output:
The value after bitwise left shift and assigning : 32
The value after bitwise right shift and assigning : 2
Next Article -
Inplace vs Standard Operators
Similar Reads
Inplace Operators in Python | Set 1 (iadd(), isub(), iconcat()...) Python in its definition provides methods to perform inplace operations, i.e. doing assignments and computations in a single statement using an operator module. Example x += y is equivalent to x = operator.iadd(x, y) Inplace Operators in PythonBelow are some of the important Inplace operators in Pyt
3 min read
Inplace vs Standard Operators in Python Inplace Operators - Set 1, Set 2Normal operators do the simple assigning job. On other hand, Inplace operators behave similarly to normal operators except that they act in a different manner in case of mutable and Immutable targets. The _add_ method, does simple addition, takes two arguments, return
3 min read
Operator Functions in Python | Set 2 Operator Functions in Python | Set 1 More functions are discussed in this article. 1. setitem(ob, pos, val) :- This function is used to assign the value at a particular position in the container. Operation - ob[pos] = val 2. delitem(ob, pos) :- This function is used to delete the value at a particul
5 min read
Operator Functions in Python | Set 1 Python has predefined functions for many mathematical, logical, relational, bitwise etc operations under the module "operator". Some of the basic functions are covered in this article. 1. add(a, b) :- This function returns addition of the given arguments. Operation - a + b. 2. sub(a, b) :- This func
5 min read
Increment += and Decrement -= Assignment Operators in Python If you're familiar with Python, you would have known Increment and Decrement operators ( both pre and post) are not allowed in it. Python is designed to be consistent and readable. One common error by a novice programmer in languages with ++ and -- operators are mixing up the differences (both in pr
3 min read