"method involving two objects" is that possible in Python?

Kurda Yon kurdayon at yahoo.com
Fri Jun 27 17:41:01 EDT 2008


Hi,

I just started to learn Python. I understood how one can create a
class and define a method related with that class. According to my
understanding every call of a methods is related with a specific
object. For example, we have a method "length", than we call this
method as the following "x.length()" or "y.length()" or "z.length()",
where z, y, and z are objects of the class.

I am wandering if it is possible to create a method which is related
not with a single object (as in the previous example) but with a pare
of objects. For example, I want to have a class for vectors, and I
want to have a methods which calculate a dot product of two vectors.
One of the possibilities is to use __mul__ and that I calculated dot
product of "x" and "y" just as "x * y". However, I am wandering if I
can declare a method in a way that allows me to calculate dot product
as "dot(x,y)".

Thank you in advance.



More information about the Python-list mailing list