Xem http://docs.python.org/library/numbers.html - int (numbers.Integral
) là loại phụ của numbers.Rational
.
>>> import numbers
>>> isinstance(1337, numbers.Integral)
True
>>> isinstance(1337, numbers.Rational)
True
>>> issubclass(numbers.Integral, numbers.Rational)
True
Mẫu số của int luôn là 1
trong khi tử số của nó là giá trị.
Trong PEP 3141 bạn tìm thấy chi tiết về việc triển khai các loại số khác nhau, ví dụ: chứng minh tuyên bố trước:
@property
def numerator(self):
"""Integers are their own numerators."""
return +self
@property
def denominator(self):
"""Integers have a denominator of 1."""
return 1
Vì khi nào là số nguyên số nguyên? – Wes