编程语言
首页 > 编程语言> > Mutable and immutable data types in Python

Mutable and immutable data types in Python

作者:互联网

Introduction (Objects, Values, and Types)

All the data in a Python code is represented by objects or by relations between objects. Every object has an identity, a type, and a value.

Identity

An object’s identity never changes once it has been created; you may think of it as the object's address in memory. The is operator compares the identity of two objects; the id() function returns an integer representing its identity.

Type

An object’s type defines the possible values and operations (e.g. "does it have a length?") that type supports. The type() function returns the type of an object. An object type is unchangeable like the identity.

Value

The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable.

Mutable and Immutable Data Types in Python

We can easily check those properties by brief code.
Above contents copy from here!

标签:Python,type,object,objects,Mutable,data,identity
来源: https://www.cnblogs.com/gbyu/p/14269500.html