Skip to Content
Introducing Python, 2nd Edition
book

Introducing Python, 2nd Edition

by Bill Lubanovic
November 2019
Beginner
630 pages
12h 20m
English
O'Reilly Media, Inc.
Audiobook available
Content preview from Introducing Python, 2nd Edition

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, they’re 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 the Python interactive interpreter, typing these snippets and seeing the results immediately. Try running them yourself with the version of Python on your computer. You’ll recognize these examples by the >>> prompt.

Booleans

In Python, the only values for the boolean data type are True and False. Sometimes, you’ll use these directly; other times you’ll evaluate the “truthiness” of other types from their values. The special Python function bool() can convert any Python data type to a boolean.

Functions get their own chapter in Chapter 9, but for now you just need to know that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Introducing Python, 3rd Edition

Introducing Python, 3rd Edition

Bill Lubanovic

Publisher Resources

ISBN: 9781492051374Errata Page