Data Types - Numbers
Integer (int) - a number that can be written without a fractional component.
Int is created when we write a number without a floating point
#Integer x = 5 print(x) type(x)
Float - a number with a fractional component.
Float is created when we write a number with a floating point
#Float x = 5.5 print(x) type(x)
Long - an integer type with unlimited length.
Long is created when we write (or calculate) a very long number (2147483647 with 32-bit system and 9223372036854775807 with 64-bit system) This type was dropped in python 3.0 and int type is used instead.
What happens when a program divides two integers (for example 5 / 3)?
Well the answer depends on the version of python running the code.
On python 2.x the result of integers division is always an integer (floor division). That means that sometimes we will not get the expected result. If you would like to get the expected result you have to convert the integers to floats. On python 3.x you don't have to worry about that. Division of integer returns a float type. The operator // operates as floor division.
|Example||Python 2.7 returns||Python 3 returns|
|5 / 3||1||1.6666666666666667|