I'd like to know how inheritance works for int
, list
, string
and other immutable types.
Basically I'd just inherit a class like this:
class MyInt(int):
def __init__(self, value):
?!?!?
I can't seem to figure out, how do I set the value like it's set for int
? If I do self.value = value
then my class will be used like this:
mi = MyInt(5)
print(mi.value) # prints 5
Whereas I want to use it like this:
mi = MyInt(5)
print(mi) # prints 5
How do I do this?