# Chapter 3, Summary

• The way a computer represents a particular kind of information is called a data type. The data type of an object determines what values it can have and what operations it supports.

• Python has several different data types for representing numeric values, including int and float.

• Whole numbers are generally represented using the int data type and fractional values are represented using floats. All of the Python numeric data types support standard, built-in

mathematical operations addition (+), subtraction (-), multiplication (*), division (/), integer

division (//), remainder (%), exponentiation (**), and absolute value (abs(x)).

• Additional mathematical functions are defined in the math library. To use these functions, a

program must first import the math library.

• Numerical results are often calculated by computing the sum or product of a sequence of

values. The loop accumulator programming pattern is useful for this sort of calculation.

• Both ints and floats are represented on the underlying computer using a fixed-length sequence of bits. This imposes certain limits on these representations. Hardware ints must be in the range −231 . . . (231 − 1) on a 32 bit machine. Floats have a finite amount of precision and cannot represent most numbers exactly.

• Python’s int data type may be used to store whole numbers of arbitrary size. Int values are automatically converted to longer representations when they become too large for underlying hardware int. Calculations involving these long ints are less efficient than those that use only small ints.

• Python automatically converts numbers from one data type to another in certain situations. For example, in a mixed-type expression involving ints and floats, Python first converts the ints into floats and then uses float arithmetic.

• Programs may also explicitly convert one data type into another using the functions float(), int(), and round().