📜  Python中的就地运算符 |设置 2 (ixor(), iand(), ipow(),…)

📅  最后修改于: 2022-05-13 01:55:42.990000             🧑  作者: Mango

Python中的就地运算符 |设置 2 (ixor(), iand(), ipow(),…)

Python中的就地运算符 |设置 1(iadd()、isub()、iconcat()…)

本文将讨论更多功能。

1. ixor() :- 此函数用于分配和异或当前值。此操作执行“ a^ = b ”操作。在不可变容器的情况下执行分配,例如字符串、数字和元组。

2. ipow() :- 该函数用于对当前值进行赋值和取幂。此操作执行“ a ** = b ”操作。在不可变容器的情况下执行分配,例如字符串、数字和元组。

# 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)

输出:

The value after xoring and assigning : 15
The value after exponentiating and assigning : 625

3. iand() :- 此函数用于按位分配当前值。此操作执行“ a &= b ”操作。在不可变容器的情况下执行分配,例如字符串、数字和元组。

4. ior() :- 该函数用于按位或当前值赋值。此操作执行“ a |=b ”操作。在不可变容器的情况下执行分配,例如字符串、数字和元组。

# 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)

输出:

The value after bitwise or, and assigning : 15
The value after bitwise and, and assigning : 4

5. ilshift() :- 此函数用于通过第二个参数分配当前值并按位左移。此操作执行“ a <<=b ”操作。在不可变容器的情况下执行分配,例如字符串、数字和元组。

6. irshift() :- 此函数用于通过第二个参数分配和按位右移当前值。该操作执行“ a >>=b ”操作。在不可变容器的情况下执行分配,例如字符串、数字和元组。

# 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)

输出:

The value after bitwise left shift and assigning : 32
The value after bitwise right shift and assigning : 2

下一篇文章 – 就地与标准运算符