5 Levels of Understanding the Mutability of Python Objects

Yang Zhou
TechToFreedom
Published in
5 min readDec 8, 2020

--

Introduction

Every Python programmer may have been confused about the mutability of objects. This concept is indeed a little difficult to understand in Python.

Unfortunately, questions related to the mutability of objects are the most popular questions in technical interviews for Python developers. Such as:

  • What is the difference between mutable and immutable objects?
  • Is Python call-by-value or call-by-reference?
  • Can a mutable object contained in an immutable object be modified?

The above questions are enough to distinguish between junior and senior Python developers.

To help you upgrade to a senior programmer, this article will explain the relative concepts through 5 levels from the appearance to the essence. After reading, answering the above questions will become very easy for you. 🎉

Level 0: Understand the Concepts of Mutable and Immutable Objects

Simply put, the mutable objects can be changed after creation. The immutable objects cannot be changed after creation. Let’s check it out by two examples:

--

--