Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The mutability and immutability distinction


In Chapter 2, Simple Data Types, we looked at the immutability issue. This is an important characteristic of Python objects. We'll need to look at some more aspects of mutability in Chapter 7, Basic Function Definitions. We'll look at how we can create our own mutable classes in Chapter 11, Class Definitions.

We've seen that Python's various classes include those which create mutable objects and those which create immutable objects. The immutable classes include all of the number classes, strings, bytes, and tuples. The tuple (247, 83, 148) object cannot be changed: we cannot assign a new value to an item with an index of 1.

A tuple object has the structure of Sequence: we can extract items based on their position. However, we cannot change the internal state of a tuple object.

A list is also a subclass of the Sequence class. We can, however, change the state of a list object without creating a new list instance.

The abstract base class definitions...