1

Apologize if this is a duplicate, tried searching. I understand that everything in python is a data type, but this is what I'm a bit confused about. So everything is an object, we have the collection class, integer, float, and other classes as children of the parent object class thinking of it as a tree of objects with say lists, tuples, and dictionaries as a child to the collection class.

So when we arbitrarily create our own data type class and defining the specific types of children / data types it will be able to handle, are we just redefining what python already has implemented? For example, say we create our own data class to handle list using the super() method and then specify that only integers could be placed into this list or strings, or whatever we may wish to be contained within this data type.

Sorry if this question is a bit confusing tried to word it as precisely as I could.

3
  • 1
    Sorry, but your question is still unclear. I don't get what you mean by "redefining what python already has implemented". If you mean are your own types always somehow based on the builtin types, then the answer is yes. Commented Feb 4, 2015 at 17:12
  • Yes thats what I meant sorry if that wasnt clear Commented Feb 4, 2015 at 17:16
  • To give an example of something for which the answer would be no: you can make your own NewList class, and even type list = NewList, but you can't replace the "real" list class or change how literals like [1,2,3] are treated. Commented Feb 4, 2015 at 17:19

1 Answer 1

1

So when we arbitrarily create our own data type class and defining the specific types of children / data types it will be able to handle, are we just redefining what python already has implemented?

This just has one short answer: yes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.