What is the relationship between .Integral and int numbers in the builtins module in Python 3

I'm new to Python, I'm a little confused about the relationship between numbers. Integral and int in the built-in module.

Then my questions are:

  • What is the relationship between .Integral and int numbers? Is it compatible with the relationship between Integer and int in Java (Integer is just a wrapper class for int)?

  • When to use numbers. Integral? Since none of the types defined in the mumbers module can be created, in which scenarios should we use these types?

Only one case that I know we can use Integral:

 # check if x is a integer
 isinstance(x, Integral)

From a link to the Python language:

"numbers.Number. They are created by numeric literals and returned as results by arithmetic operators and arithmetic inline functions."

, . - .

>>> a,b=123,5
>>> c=a*b
>>> print(c.__class__)
<class 'int'>
>>> d=abs(a)
>>> print(d.__class__)
<class 'int'>

Python 3.2a3.

+3
1

, Java: numbers.Integral "" ( , " " (ABC)) . , .

, , - int.

isinstance( obj, numbers.Integral) , obj :

>>> isinstance(3, numbers.Integral)
True
>>> isinstance(3.0, numbers.Integral)
False
>>> isinstance(3+0j, numbers.Integral)
False

, , numbers.Integral - , .

+3

Source: https://habr.com/ru/post/1776992/


All Articles