Photo by Baher Khairy on Unsplash

6 Things to Understand Python Data Mutability

Immutable vs. Mutable

Yong Cui
Published in
8 min readApr 8, 2020

--

Data mutability isn’t a topic that we encounter early in our Python learning course. However, understanding this topic is a crucial step to becoming a more seasoned Python programmer.

In this article, I’d like to share six fundamental notions that can help you get some insights into this topic. Notably, we can’t fully clarify data mutability in isolation with other crucial concepts, such as objects and introspections, and thus we’ll begin our discussion on these related topics first.

1. Objects: Identity, Type, and Value

As an object-oriented programming language, Python uses objects everywhere. Everything in Python is an object, including built-in data types (e.g., integers, strings), functions, classes, and even modules.

But what are objects in Python? In essence, objects represent tangible data containers that form a human-computer interface. Programmers write code to directly manipulate these containers to implement specific functionalities in a way that computers can understand.

  • Identity. Under the hood, you can consider that objects are blocks of data occupying somewhere in the memory. In Python, we use the memory addresses of these blocks to identify objects. More…

--

--

Yong Cui
The Startup

Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/python-how-to).