當前位置: 首頁>>代碼示例>>Python>>正文


Python operator.__div__方法代碼示例

本文整理匯總了Python中operator.__div__方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.__div__方法的具體用法?Python operator.__div__怎麽用?Python operator.__div__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在operator的用法示例。


在下文中一共展示了operator.__div__方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testMath

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __div__ [as 別名]
def testMath(self):
        self.failUnlessEqual(str(-scalar(name="s")), "unnamed_scalar{=-1.0} * s")
        self.failUnlessEqual(str(scalar(name="s") + scalar(name="t")), "s  +  t")
        self.failUnlessEqual(str(scalar(name="s") + 1), "s  +  unnamed_scalar{=1.0}")
        self.failUnlessEqual(str(1 + scalar(name="s")), "s  +  unnamed_scalar{=1.0}")
        self.failUnlessEqual(str(scalar(name="s") - scalar(name="t")), "unnamed_scalar{=-1.0} * t  +  s")
        self.failUnlessEqual(str(1 - scalar(name="s")), "unnamed_scalar{=-1.0} * s  +  unnamed_scalar{=1.0}")
        self.failUnlessEqual(str(2 * scalar(name="s")), "s * unnamed_scalar{=2.0}")
        self.failUnlessEqual(str(scalar(name="s") * 2), "s * unnamed_scalar{=2.0}")
        self.failUnlessEqual(str(scalar(name="s") * scalar(name="t")), "s * t")
        self.failUnlessEqual(str((scalar(name="s") + scalar(name="t")) * 2), "s * unnamed_scalar{=2.0}  +  t * unnamed_scalar{=2.0}")
        self.failUnlessEqual(str(scalar(name="s") / 2.0), "unnamed_scalar{=0.5} * s")
        self.failUnlessEqual(str(scalar(name="s") / 2), "unnamed_scalar{=0.0} * s") # integer logic!
        self.failUnlessEqual(str((scalar(name="s") + scalar(name="t")) / 2.0), "unnamed_scalar{=0.5} * s  +  unnamed_scalar{=0.5} * t")
        self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, 2, scalar())
        self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, scalar(), scalar())
        self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, vector(1), scalar())
        self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, scalar() + scalar(), scalar())
        self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, vector(1) + vector(1), scalar()) 
開發者ID:pyx-project,項目名稱:pyx,代碼行數:21,代碼來源:test_solve.py

示例2: triplet_to_fractional_rgb

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __div__ [as 別名]
def triplet_to_fractional_rgb(rgbtuple):
    return map(operator.__div__, rgbtuple, _maxtuple) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:4,代碼來源:ColorDB.py

示例3: __div__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __div__ [as 別名]
def __div__(self, other):
        return self._operation(other, operator.__div__) 
開發者ID:mementum,項目名稱:backtrader,代碼行數:4,代碼來源:lineroot.py

示例4: __rdiv__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __div__ [as 別名]
def __rdiv__(self, other):
        return self._roperation(other, operator.__div__) 
開發者ID:mementum,項目名稱:backtrader,代碼行數:4,代碼來源:lineroot.py

示例5: __div__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import __div__ [as 別名]
def __div__(self, other):
        return Null() 
開發者ID:ChrisBeaumont,項目名稱:soupy,代碼行數:4,代碼來源:soupy.py


注:本文中的operator.__div__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。