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

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically