Integer & Float Data Types

code guest
Python Journey
Published in
2 min readAug 8, 2019

Python doesn’t have a single number data type for numbers. Instead, it uses three different data types — float, integer and complex number data types for numerical information.

Firstly, why is there a need to store numerical information separately from strings (aka. text information)? Because numerical data like 123 or 0.175 can be used directly in calculations.

The difference between float and integer is that float has decimal places whereas integer doesn’t.

Therefore, if we want to store a number with decimal points, we would store it as a float.

The value of pi is stored as a float. (credits: undraw.co)

If we want to store whole numbers, we would use integers. When we work with complex numbers, we would use the complex number data type.

We can recognise numerical data belonging to these data types when we see digits without quotes around them.

10 and “10” look similar but 10 is an integer and can be used directly in mathematical calculations (eg. 10*10) while “10” is a string and we cannot do math with it.

Summary

  • Numerical information is stored using integer, float or complex number data type
  • The difference between integer and float lies in the presence of decimals
  • Integers and floats are not enclosed by anything

External links

Quiz

Which options are false?

a) “123” is an integer

b) Integers and floats can be used directly in calculations while strings cannot

c) 123.05 is a float

d) An integer cannot be added to a float

Quiz explanation

a) “123” is a string. Integers and floats are not enclosed by quotes.

b) Option (b) is accurate

c) Option (c) is accurate

d) Integers and floats both convey numerical information — they can be added to each other — producing a float.

Quiz answers: b & c

--

--