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
Why Are There No ++ and -- Operators in Python?
Python does not include the ++ and -- operators that are common in languages like C, C++, and Java. This design choice aligns with Python's focus on simplicity, clarity, and reducing potential confusion. In this article, we will see why Python does not include these operators and how you can achieve
3 min read
Chaining comparison operators in Python
Checking multiple conditions in a single expression is common in programming. In Python, comparison operator chaining allows us to write cleaner, more readable code when evaluating multiple conditions. Instead of using multiple and conditions, Python enables chaining comparisons directly in a mathem
4 min read
Infinite Iterators in Python
Iterator in Python is any python type that can be used with a âfor in loopâ. Python lists, tuples, dictionaries, and sets are all examples of inbuilt iterators. But it is not necessary that an iterator object has to exhaust, sometimes it can be infinite. Such type of iterators are known as Infinite
2 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
Python Membership and Identity Operators
There is a large set of Python operators that can be used on different datatypes. Sometimes we need to know if a value belongs to a particular set. This can be done by using the Membership and Identity Operators. In this article, we will learn about Python Membership and Identity Operators.Python Me
5 min read
Assignment Operators in Python
The Python Operators are used to perform operations on values and variables. These are the special symbols that carry out arithmetic, logical, and bitwise computations. The value the operator operates on is known as the Operand. Assignment Operators are used to assign values to variables. This opera
7 min read