Part 1 · Section 04

Numeric Types

Numbers look simple until you ask how a computer actually stores them. Python offers several numeric types, and each one makes a different trade-off between exactness, range, speed and memory. Knowing those trade-offs explains why 0.1 + 0.1 + 0.1 == 0.3 is False, why round(2.5) is 2, why -7 // 2 is -4, and when you should reach for Decimal or Fraction instead of float.

The section ends with booleans, which turn out to be integers in disguise, and with the rules for truthiness, short-circuiting and comparisons that every if statement relies on.

In this section you’ll learn:

Lectures

  1. 01Integers - Data Type✓
  2. 02Integers - Operations✓
  3. 03Integers - Constructors and Bases✓
  4. 04Rational Numbers✓
  5. 05Floats - Internal Representation✓
  6. 06Floats - Equality Testing✓
  7. 07Floats - Coercing to Integers✓
  8. 08Floats - Rounding✓
  9. 09Decimals✓
  10. 10Decimals - Constructors and Contexts✓
  11. 11Decimals - Math Operations✓
  12. 12Decimals - Performance Considerations✓
  13. 13Complex Numbers✓
  14. 14Booleans✓
  15. 15Booleans - Truth Values✓
  16. 16Booleans - Precedence and Short-Circuiting✓
  17. 17Booleans - Boolean Operators✓
  18. 18Comparison Operators✓

Practice: quiz & exercises

12 quiz questions · 4 coding exercises

Go to practice →