本文整理匯總了Python中operator.__pow__方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.__pow__方法的具體用法?Python operator.__pow__怎麽用?Python operator.__pow__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類operator
的用法示例。
在下文中一共展示了operator.__pow__方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_pow
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __pow__ [as 別名]
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)
示例2: __pow__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __pow__ [as 別名]
def __pow__(self, other):
return self._operation(other, operator.__pow__)
示例3: __rpow__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __pow__ [as 別名]
def __rpow__(self, other):
return self._roperation(other, operator.__pow__)
示例4: _string_to_operator
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __pow__ [as 別名]
def _string_to_operator(self):
operators = {
"+": operator.__add__,
"-": operator.__sub__,
"*": operator.__mul__,
"**": operator.__pow__,
"/": operator.__truediv__,
"//": operator.__floordiv__,
}
return operators[self.operator]
### PUBLIC PROPERTIES ###
示例5: test_pow
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __pow__ [as 別名]
def test_pow(self):
self.failUnlessRaises(TypeError, operator.pow)
self.failUnlessRaises(TypeError, operator.pow, None, None)
self.failUnless(operator.pow(3,5) == 3**5)
self.failUnless(operator.__pow__(3,5) == 3**5)
self.assertRaises(TypeError, operator.pow, 1)
self.assertRaises(TypeError, operator.pow, 1, 2, 3)