Chapter 3. Numbers

That action is best which procures the greatest happiness for the greatest numbers.

Francis Hutcheson

In this chapter we begin by looking at Python’s simplest built-in data types:

  • Booleans (which have the value True or False)

  • Integers (whole numbers such as 42 and 100000000)

  • Floats (numbers with decimal points such as 3.14159, or sometimes exponents like 1.0e8, which means one times ten to the eighth power, or 100000000.0)

In a way, these basic data types are like atoms. We use them individually in this chapter, and in later chapters you’ll see how to combine them into larger “molecules” like lists and dictionaries.

Each type has specific rules for its usage and is handled differently by the computer. I also show how to use literal values like 97 and 3.1416, and the variables that I mentioned in Chapter 2.

The code examples in this chapter are all valid Python, but they’re snippets. We’ll be using ...

Get Introducing Python, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.