Chart of mutable to immutable types

Is there a table or diagram somewhere on the network that shows which types (built-in) are mutable and immutable in python?

+7
source share
1 answer

I am not sure about the diagram, but basically:

Mutable:

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

Invariable:

tuple , str

You can check for variability with:

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

For a dictionary (collation):

 >>> isinstance({}, collections.MutableMapping) True 
+10
source

All Articles