Let's say I have following code:
mystring='abcd'
print(type(mystring))
Python understands that mystring is a string object and returns <class 'str'>. How does this happen?
What if I want to declare my own data type that supports the same logic, that is when I type print(type(mystring)) I receive <class 'myClass'>, not python default class <class 'str'>. How can I achieve that?
Update: I am interested in how to rearrange the logic of class auto-definition? I don't want to declare variable explicitly as an object of myClass by myString = myClass('abcd'). I just want to type myString = 'abcd' and be sure that Python has defined myString as instance of myClass. Is that possible? May be it is all about inheritance/overriding str class?
str, what else would happen?typeis just a class, the class of all classes, i.e. a metaclass if you want to know a little more about how it all worksMyClass.'abcd'is always in instance ofstr, you can't make it something else without being explicit about it.