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.
import operator
x = operator.ixor( 10 , 5 );
print ( "The value after xoring and assigning : " ,end = "")
print (x)
x = operator.ipow( 5 , 4 );
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.
import operator
x = operator.ior( 10 , 5 );
print ( "The value after bitwise or, and assigning : " ,end = "")
print (x)
x = operator.iand( 5 , 4 );
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.
import operator
x = operator.ilshift( 8 , 2 );
print ( "The value after bitwise left shift and assigning : " ,end = "")
print (x)
x = operator.irshift( 8 , 2 );
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
Share your thoughts in the comments
Please Login to comment...