开发者

Chart of mutable versus immutable types

Is there a table or a chart somewhere online which shows what types (inbuilt) are mutable and immutable in开发者_如何学Python python?


I am not sure of a chart, but basically:

Mutable:

list, dictionary, bytearray Note: bytearray is not a sequence though.

Immutable:

tuple, str

You can check for mutability with:

>>> import collections
>>> l = range(10)
>>> s = "Hello World"
>>> isinstance(l, collections.MutableSequence)
True
>>> isinstance(s, collections.MutableSequence)
False

For a dictionary (mapping):

>>> isinstance({}, collections.MutableMapping)
True
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜