I want to know about immutable type as I am very much confused about that topic. I understand the floating object is considered to be immutable, with this kind of example from my book:
class RoundFloat(float):
def __new__(cls, val):
return float.__new__(cls, round(val, 2))
Is this considered to be immutable because of the class structure/hierarchy?
class SortedKeyDict(dict):
def __new__(cls, val):
return dict.__new__(cls, val.clear())
Whereas something mutable has functions inside the class, with this type of example:
class SortedKeyDict_a(dict):
def example(self):
return self.keys()
Also, for the last class(SortedKeyDict_a), if I pass this type of set to it:
d = (('zheng-cai', 67), ('hui-jun', 68),('xin-yi', 2))
without referring to the example function, it returns a dictionary.