[Python Advanced Tutorial 16] Mutable objects and immutable objects

insert image description here

In Python, all data types can be divided into two categories: mutable objects (Mutable) and immutable objects (Immutable). This is an important concept in Python, which affects the behavior of variable assignment, function parameter passing, and data modification.

1. Mutable objects

A mutable object means that its internal data can be modified after creation without changing its identity (id). That is to say, the content of the mutable object can be modified, but its reference address will not change.

Common mutable objects are:

  • list
  • dictionary (dict)
  • set

Example:

# 列表是可变对象
my_list = [

Guess you like

Origin blog.csdn.net/m0_47256162/article/details/132162486