Chapter 1. Primitives
Computer programs manipulate data. This chapter describes the simplest kinds of
Python data and the simplest ways of
manipulating them. An individual item of data is called a value. Every value in Python has
a type that identifies the
kind of value it is. For example, the type of 2 is int.
You’ll get more comfortable with the concepts of types and values as you see
more examples.
The Preface pointed out that Python is a multiparadigm programming language. The terms “type” and “value” come from traditional procedural programming. The equivalent object-oriented terms are class and object. We’ll mostly use the terms “type” and “value” early on, then gradually shift to using “class” and “object” more frequently. Although Python’s history is tied more to object-oriented programming than to traditional programming, we’ll use the term instance with both terminologies: each value is an instance of a particular type, and each object is an instance of a particular class.
Simple Values
Types for some simple kinds of values are an integral part of Python’s
implementation. Four of these are used far more frequently than others:
logical (Boolean), integer,
float, and string. There is also
a special no-value value called None.
When you enter a value in the Python interpreter, it prints it on the following line:
>>> 90
90
>>>When the value is None, nothing is
printed, since None means
“nothing”:
>>> None
>>>If you type something Python finds unacceptable in some way, you will see ...