Do I need "self" and "other"?

Kurda Yon kurdayon at
Sat Jun 28 00:17:33 CEST 2008


I found one example which defines the addition of two vectors as a
method of a class. It looks like that:

class Vector:
  def __add__(self, other):
    data = []
    for j in range(len(
      data.append([j] +[j])
    return Vector(data)

In this example one uses "self" and "other". Does one really need to
use this words? And, if yes, why? I have replaced "self" by "x" and
"other" by "y" and everything looks OK. Is it really OK or I can have
some problem in some cases?

Thank you!

More information about the Python-list mailing list