General Object Properties

Now that we’ve seen all of Python’s built-in types, let’s take a quick look at some of the properties they share. Some of this section is a review of ideas we’ve already seen at work.

Type Categories Revisited

Table 2.11 classifies all the types we’ve seen, according to the type categories we introduced earlier. As we’ve seen, objects share operations according to their category—for instance, strings, lists, and tuples all share sequence operations. As we’ve also seen, only mutable objects may be changed in place. You can change lists and dictionaries in place, but not numbers, strings, or tuples.[17] Files only export methods, so mutability doesn’t really apply (they may be changed when written, but this isn’t the same as Python type constraints).

Table 2-11. Object Classifications

Object type

Category

Mutable?

Numbers

Numeric

No

Strings

Sequence

No

Lists

Sequence

Yes

Dictionaries

Mapping

Yes

Tuples

Sequence

No

Files

Extension

N/A

Get Learning Python 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.