int.numerator
and int.denominator
are a mystery to me.
help(int.numerator)
states:
the numerator of a rational number in lowest terms
But as far as I know, int
is not a rational number. So why do these properties exist?
One simple way to understand a fraction is to imagine a pizza. The denominator shows you how many equal pieces the pizza is divided into, and the numerator represents how many of those pieces you have. In Latin, numerator means "counter or numberer."
The meaning of the denominator is the divisor of a fraction. The denominator is the number or integer that is below the horizontal line in a fraction. Whereas the numerator lies above the line in a fraction.
Fractionis used to create a Fraction object. It takes Numerator and Denominator. The default value of the numerator is 0 and denominator is 1. It raises ZeroDivisionError when the denominator is 0. At first we will see how the class can create fractions using Numerator and Denominator.
Improper fractions – in this type of fraction, the numerator has a greater value than the denominator. Solving mixed fractions results in improper fractions. For example- 7/2, 11/5, 7¾, and so on. Proper fractions – in proper fractions, the numerator has a lower value than the denominator.
See http://docs.python.org/library/numbers.html - int (numbers.Integral
) is a subtype of numbers.Rational
.
>>> import numbers >>> isinstance(1337, numbers.Integral) True >>> isinstance(1337, numbers.Rational) True >>> issubclass(numbers.Integral, numbers.Rational) True
The denominator of an int is always 1
while its numerator is the value itself.
In PEP 3141 you find details about the implementation of the various number types, e.g. proving the previous statement:
@property def numerator(self): """Integers are their own numerators.""" return +self @property def denominator(self): """Integers have a denominator of 1.""" return 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With