Skip to Content
Introducing Python
book

Introducing Python

by Bill Lubanovic
November 2014
Beginner content levelBeginner
481 pages
10h 11m
English
O'Reilly Media, Inc.
Content preview from Introducing Python

Chapter 2. Py Ingredients: Numbers, Strings, and Variables

In this chapter we’ll 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)

  • strings (sequences of text characters)

In a way, they’re like atoms. We’ll use them individually in this chapter. Chapter 3 shows how to combine them into larger “molecules.”

Each type has specific rules for its usage and is handled differently by the computer. We’ll also introduce variables (names that refer to actual data; more on these in a moment).

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. In Chapter 4, we start writing Python programs that can run on their own.

Variables, Names, and Objects

In Python, everything—booleans, integers, floats, strings, even large data structures, functions, and programs—is implemented as an object. This gives the language a consistency (and useful features) that some other languages lack.

An object is like a clear plastic box that contains a piece of data (Figure 2-1). The object has a type ...

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.
Start your free trial

You might also like

Introducing Python, 2nd Edition

Introducing Python, 2nd Edition

Bill Lubanovic
Introduction to Python

Introduction to Python

Jessica McKellar
Fluent Python

Fluent Python

Luciano Ramalho
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781449361167Errata Page