Python integers and floating-point numbers
Use a stock quote to distinguish whole-number share counts from decimal prices and recognize that decimal values can be approximate.
Amara's trading app shows she holds 9 shares, small pieces of a company, priced at $32.00 each. She types both numbers into Python, and it shows 9 and 32.0. Why does the price keep a decimal point when the count doesn't?
Start the lesson
4 minutes. No account needed.
What you'll learn
- An integer, or
int, is a whole number typed with no decimal point, like a count of 9 shares. - A float is a number with a decimal point, so Python shows a price typed as
32.00as32.0. - Floats store many decimals, like 0.1 and 0.2, only approximately, so
0.1 + 0.2shows0.30000000000000004. - Prices go into Python without money marks, so $1,280.50 is typed as
1280.50. - Some decimals, like
0.5, are stored exactly, so not every float is wrong.