Change language

In-Place Operators in Python | Set 2 (ixor (), iand (), ipow (), …)

|

Additional features are discussed in this article.

1. ixor () : — This function is used to assign and change the current value . This operation performs the operation " a ^ = b ". The not assignment is true for immutable containers such as strings, numbers, and tuples.

2. ipow () : — This function is used to assign and exponentiate the current value . This operation performs the operation " a ** = b ". The not assignment is true for immutable containers such as strings, numbers, and tuples.

# Python code to demonstrate how it works
# ixor () and ipow ()

 
# import statement to handle statement operations

import operator

 
# using ixor () to exclude or and assign a value

x = operator.ixor ( 10 , 5 ); 

 
# print the changed value

print ( "The value after xoring and assigning:" , end = "")

print (x)

 
# using ipow () to exponentiate and assign a value

x = operator.ipow ( 5 , 4 ); 

 
# print the changed 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 both bitwise and current values ​​. This operation performs the operation “ a & amp; = b ". The not assignment is true for immutable containers such as strings, numbers, and tuples.

4. ior () : — This function is used to assignment and bitwise or current value . This operation performs the operation “ a | = b ". The not assignment is true for immutable containers such as strings, numbers, and tuples.

# Python code to demonstrate how it works
# ior () and iand ()

 
# import statement to handle statement operations

import operator

 
# using ior () for or, and assign a value

x = operator.ior ( 10 , 5 ); 

 
# print the changed value

print ( "The value after bitwise or, and assigning:" , end = "")

print (x)

 
# using iand () for and, and assign a value

x = operator.iand ( 5 , 4 ); 

 
# print the changed 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 shift the current value by the second argument . This operation performs the operation " a "& lt; = b ". The not assignment is true for immutable containers such as strings, numbers, and tuples.

6. irshift () : — This function is used to assign and bitwise offset the rights of the current value as the second argument . This operation performs the operation " a"" = b ". The not assignment is true for immutable containers such as strings, numbers, and tuples.

# Python code to demonstrate how it works
# ilshift () and irshift ()

 
# import statement to handle statement operations

import operator

 
# using ilshift () to shift left and assign value

x = operator.ilshift ( 8 , 2 ); 

 
# print the changed value

print ( "The value after bitwise left shift and assigning:" , end = "")

print (x)

 
# use irshift () to bitwise shift right and assign a value

x = operator.irshift ( 8 , 2 ); 

 
# print the changed 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 — at Manjeet Singh . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method