本文整理汇总了Python中fractions.Fraction.__sub__方法的典型用法代码示例。如果您正苦于以下问题:Python Fraction.__sub__方法的具体用法?Python Fraction.__sub__怎么用?Python Fraction.__sub__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fractions.Fraction
的用法示例。
在下文中一共展示了Fraction.__sub__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: F
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import __sub__ [as 别名]
class F(Fraction):
'''
Classe que representa um numero fracionario, extendendo fractions.Fraction, e implentando a lógica o "M grande"
'''
def __init__(self,n,m=Fraction(0)):
self.fraction = Fraction(n)
self.m = Fraction(m)
def __repr__(self):
"""repr(self)"""
return str(float(self.fraction)) if self.m == 0 else str(float(self.fraction)) + ' + (' + str(float(self.m)) + '*M)'
def __str__(self):
"""str(self)"""
return str(float(self.fraction)) if self.m == 0 else str(float(self.fraction)) + ' + (' + str(float(self.m)) + '*M)'
def __eq__(self, f):
"""a == b"""
if type(f) is not type(self):
f = F(f)
return self.fraction.__eq__(f.fraction) and self.m.__eq__(f.m)
def __add__(self, f):
"""a + b"""
if type(f) is not type(self):
f = F(f)
return F(self.fraction.__add__(f.fraction),self.m.__add__(f.m))
def ___sub__(self, f):
"""a - b"""
if type(f) is not type(self):
f = F(f)
return F(self.fraction.__sub__(f.fraction),self.m.___sub__(f.m))
def __mul__(self, f):
"""a * b"""
if type(f) is not type(self):
f = F(f)
if f.m == 0:
return F(self.fraction.__mul__(f.fraction))
else:
return F(self.fraction.__mul__(f.fraction),self.m.__mul__(f.m))
def __div__(self, f):
"""a / b"""
if type(f) is not type(self):
f = F(f)
if f.m == 0:
return F(self.fraction.__div__(f.fraction))
else:
return F(self.fraction.__div__(f.fraction),self.m.__div__(f.m))
def __lt__(self, f):
"""a < b"""
if type(f) is not type(self):
f = F(f)
if self.m == f.m:
return self.fraction.__lt__(f.fraction)
else:
return self.m.__lt__(f.m)
def __gt__(self, f):
"""a > b"""
if type(f) is not type(self):
f = F(f)
if self.m == f.m:
return self.fraction.__gt__(f.fraction)
else:
return self.m.__gt__(f.m)
def __le__(self, f):
"""a <= b"""
if type(f) is not type(self):
f = F(f)
if self.m == f.m:
return self.fraction.__le__(f.fraction)
else:
return self.m.__le__(f.m)
def __ge__(self, f):
"""a >= b"""
if type(f) is not type(self):
f = F(f)
if self.m == f.m:
return self.fraction.__ge__(f.fraction)
else:
#.........这里部分代码省略.........