Python 2.x supports 4 built-in numeric types - int, long, float and complex. Of these, the long type has been dropped in Python 3.x - the int type is now of unlimited length by default. You don’t have to specify what type of variable you want; Python does that automatically.
In general, the number types are automatically 'up cast' in the following order:
Int → Long → Float → Complex. The farther to the right you go, the higher the precedence.
>>>x=5>>>type(x)<type'int'>>>>x=187687654564658970978909869576453>>>type(x)<type'long'>>>>x=1.34763>>>type(x)<type'float'>>>>x=5+2j>>>type(x)<type'complex'>
The result of divisions is somewhat confusing. In Python 2.x, using the / operator on two integers will return another integer, using floor division. For example,5/2 will give you 2. At least one of the operands must be float to get true division, e.g.5/2. or5./2 (the dot makes a number a float) will yield 2.5. Starting with Python 2.2 this behavior can be changed to true division by the future division statementfrom __future__ import division. In Python 3.x, the result of using the / operator is always true division (you can ask for floor division explicitly by using the // operator since Python 2.2).
This illustrates the behavior of the / operator in Python 2.2+:
>>>5/22>>>5/2.2.5>>>5./22.5>>>from__future__importdivision>>>5/22.5>>>5//22
For operations on numbers, see chaptersBasic Math andMath.