What Is a Type?

We’ve now seen two types of numbers (integers and floating-point numbers), so we ought to explain what we mean by a type. In computing, a type consists of two things:

  • a set of values, and
  • a set of operations that can be applied to those values.

For example, in type int, the values are …, -3, -2, -1, 0, 1, 2, 3, … and we have seen that these operators can be applied to those values: +, -, *, /, //, %, and **.

The values in type float are a subset of the real numbers, and it happens that the same set of operations can be applied to float values. If an operator can be applied to more than one type of value, it is called an overloaded operator. We can see what happens when these are applied to various values in Table 1,

Get Practical Programming, 2nd 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.