我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用operator.__pow__()。
def __pow__(self, rhs): return op_binary(self, rhs, operator.__pow__)
def __rpow__(self, lhs): return op_binary(lhs, self, operator.__pow__)
def __ipow__(self, v): return self.op_binary_inplace(v, operator.__pow__)
def __pow__(self, rhs): return op_binary(self, rhs, operator.__pow__) # Reflected binary operation
def __rpow__(self, lhs): return op_binary(lhs, self, operator.__pow__) # In-place operations
def test_pow(self): self.assertRaises(TypeError, operator.pow) self.assertRaises(TypeError, operator.pow, None, None) self.assertEqual(operator.pow(3,5), 3**5) self.assertEqual(operator.__pow__(3,5), 3**5) self.assertRaises(TypeError, operator.pow, 1) self.assertRaises(TypeError, operator.pow, 1, 2, 3)
def test_pow(self): self.assertRaises(TypeError, operator.pow) self.assertRaises(TypeError, operator.pow, None, None) self.assertTrue(operator.pow(3,5) == 3**5) self.assertTrue(operator.__pow__(3,5) == 3**5) self.assertRaises(TypeError, operator.pow, 1) self.assertRaises(TypeError, operator.pow, 1, 2, 3)
def __pow__(self, power, modulo=None): with self._lock: return pow(self.__wrapped__, power, modulo)
def __rpow__(self, other): with self._lock: return operator.__pow__(other, self.__wrapped__)