runtime
07 / 250
lesson 07 Variables & Data Types · beginner

Whole numbers and decimals

A whole number and a decimal are different values, even when they look similar.

You'll be able to
  • Store a whole number and print it
  • Store a decimal and print it
  • Tell 8 from 8.0 in the console
The idea

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.

example-1.py · Two kinds of number
count = 8
price = 8.0
print(count)
print(price)
example-2.py · A price and a refund
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).

Review
  • 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.

Loading your progress…

To master this lesson, solve both challenges without hints or the answer, and pass the concept check.

Whole numbers and decimals — Variables & Data Types · Runtime