I guess it would be easy for me to explain the question with an examply
Suppose I want to write my own vector class.
And in that class let say i want to define a method to add 2 vectors
something like:
class vector:
.....
def add(self,other):
----some code
so basically what this will do is.. if a vector is vec
then
vec.add(othervec)
will do the addition..
but how do i do this..
its like inherting your own class..datatype
?
Thanks
If you want to add two classes, I’d look at the
__add__function, which allows you to do normal addition (and not call.add()):As for your question, I’m not exactly sure about what you’re asking. I wrote my
Vector()class like this: