ElasticON Tour is coming to a city near you!   See all locations

Python Mutable and Immutable en

In Python, everything is an object. An object has its own internal state. Some objects allow you to change their internal state and others don’t.
Content highlight

An object whose internal state can be changed is called a mutable object, while an object whose internal state cannot be changed is called an immutable object.

The following are examples of immutable objects:

And the following are examples of mutable objects:

User-defined classes can be mutable or immutable, depending on whether their internal state can be changed or not.

Python immutable example

When you declare a variable and assign its an integer, Python creates a new integer object and sets the variable to reference that object:

Theo nguyễn tiến thành

Tin liên quan

Từ khóa: 
Bình luận (10)
Ý kiến của bạn sẽ được xét duyệt trước khi đăng. Xin vui lòng gõ tiếng Việt có dấu
Hiện chưa có bình luận nào, hãy trở thành người đầu tiên bình luận cho bài viết này!