本文整理汇总了Python中fractions.Fraction.__str__方法的典型用法代码示例。如果您正苦于以下问题:Python Fraction.__str__方法的具体用法?Python Fraction.__str__怎么用?Python Fraction.__str__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fractions.Fraction
的用法示例。
在下文中一共展示了Fraction.__str__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Rational
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import __str__ [as 别名]
class Rational(Number):
""" Purely a wrapper for the builtin fraction class
"""
def __init__(self, *args):
self.value = Fraction(*args).limit_denominator()
super(Rational, self).__init__()
self.numerator = self.value.numerator
self.denominator = self.value.denominator
def __str__(self):
return self.value.__str__()
示例2: __str__
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import __str__ [as 别名]
def __str__(self):
''' returns a string representation "numerator/denominator" of self
raises an Exception if the fraction is not in the probability range, from 0 to 1
'''
self.check()
return Fraction.__str__(self)
示例3: check
# 需要导入模块: from fractions import Fraction [as 别名]
# 或者: from fractions.Fraction import __str__ [as 别名]
def check(self):
''' raises an Exception if the fraction is not in the probability range, from 0 to 1
'''
if not (0 <= self <= 1):
raise ProbFraction.Error("%s is not a valid probability (between 0 and 1)"%Fraction.__str__(self))