Whole numbers and decimals
A whole number and a decimal are different values, even when they look similar.
- Store a whole number and print it
- Store a decimal and print it
- Tell 8 from 8.0 in the console
A whole number has no decimal point: 8. A decimal has one: 8.0. Python prints them differently, so you can see which kind you stored. A minus sign in front makes a negative number, as in -3. Counts (items, people, days) are usually whole numbers. Money and measurements are usually decimals. Adding and subtracting come in the next module.
Run each example to see what it prints. Running examples doesn't count toward progress.
count = 8 price = 8.0 print(count) print(price)
price = 43.77 refund = -3 print("Price:", price) print("Refund:", refund)
Mistake to avoid: the decimal point in Python is a dot, never a comma. price = 12,5 doesn't store twelve and a half. It stores two separate numbers, 12 and 5, and printing it shows (12, 5).
- A whole number has no decimal point. A decimal has one, and it is a dot.
- Python prints 8 and 8.0 differently.
- A minus written against the digits is part of the number. Next: text, True and False.