object types, mutable or not?

Mike McClain mike.junk.46 at att.net
Sun May 13 16:02:01 EDT 2018


I'm new to Python and OOP.
Python  en 2.7.14 Documentation  The Python Language Reference
3. Data model
3.1. Objects, values and types
An object's type is also unchangeable. [1]
[1]     It is possible in some cases to change an object's type,
    under certain controlled conditions.

It appears to me as if an object's type is totally mutable and
solely dependant on assignment.

>>> obj = 'a1b2'
>>> obj
'a1b2'
>>> type (obj)
<type 'str'>
>>>
>>> obj = list(obj)
>>> obj
['a', '1', 'b', '2']
>>> type (obj)
<type 'list'>
>>>
>>> obj = dict( zip(obj[0::2],obj[1::2]) )
>>> type (obj)
<type 'dict'>
>>> obj
{'a': '1', 'b': '2'}

At what level does my understanding break down?

Thanks,
Mike
--
One reason experience is such a good teacher
    is that she doesn't allow dropouts.



More information about the Python-list mailing list