5/19 General question dot notation example



I completed the example, but I was curious why in the dot notation example they did not pass 'sides' to init, like we had to do for the example?

class Square(object):
  def __init__(self):
    self.sides = 4

my_shape = Square()
print my_shape.sides


Because the class is called Square. It would be possible, but not logical to take sides as input to __init__, because a square always has 4 sides.


I see, so you don't need to input all the variables that correspond to the attributes you want for a given function, only the ones that change?

for example, the exercise has you input 'name', but only b/c that changes

class Animal(object):
def init(self,name):
print zebra.name

but the example just has self.sides as a constant, so it's not listed in the input for the variable

class Square(object):
def init(self):
self.sides = 4

my_shape = Square()
print my_shape.sides

is this correct?


It's a rule of thumb which will work in many cases. It's not a rule that's part of python, but just one that gives you a general idea.