0

I read that self is not a keyword in python, but why the following code outputs: (10, 10)???

One of my function use selff and other one use self.

I use python 2.7.

class Point:
    def __init__(selff, x=0, y=0):
        selff.x = x
        selff.y = y
    def __str__(self):
        return "({0}, {1})".format(self.x, self.y)

p1 = Point(10,10)
print p1
Tail of Godzilla
  • 531
  • 1
  • 6
  • 20
  • It should always be `self` for member variables. – Dylan Lawrence Dec 04 '15 at 17:04
  • 2
    Because it's first argument that python is secretly passing to those methods. You could technically name it whatever you want, but the same object (a reference to itself) is always going to be put there. – MrAlexBailey Dec 04 '15 at 17:04
  • @DylanLawrence It doesn't have to be `self` but the convention is strong with this one. – Peter Wood Dec 04 '15 at 17:10
  • @PeterWood I don't think I've ever seen anyone call it anything else, it might technically be changeable, but incredibly inadvisable. – Dylan Lawrence Dec 04 '15 at 17:14

0 Answers0