Chapter 4. Numbers
This chapter begins our tour of the Python language. In Python, data takes the form of objects—either built-in objects that Python provides, or objects we create using Python and C tools. Since objects are the most fundamental notion in Python programming, we’ll start this chapter with a survey of Python’s built-in object types before concentrating on numbers.
Python Program Structure
By way of introduction, let’s first get a clear picture of how this chapter fits into the overall Python picture. From a more concrete perspective, Python programs can be decomposed into modules, statements, expressions, and objects, as follows:
Programs are composed of modules.
Modules contain statements.
Statements contain expressions.
Expressions create and process objects.
We introduced the highest level of this hierarchy when we learned about modules in Chapter 3. This part’s chapters begin at the bottom, exploring both built-in objects, and the expressions you can code to use them.
Why Use Built-in Types?
If you’ve used lower-level languages such as C or C++, you know that much of your work centers on implementing objects—also known as data structures—to represent the components in your application’s domain. You need to lay out memory structures, manage memory allocation, implement search and access routines, and so on. These chores are about as tedious (and error prone) as they sound, and usually distract from your programs’ real goals.
In typical Python programs, most of this grunt ...
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