0

For class definitions in Python, class Name(object) gets an argument of Object. On below code, I tried to use the class without having this argument "Object" and the code still works fine.

What is the purpose of having the object there? Does this have a special meaning in Python just like init does?

class Vector(object):
def __init__(self, coordinates):
    try:
        if not coordinates:
            raise ValueError
        self.coordinates = tuple(coordinates)
        self.dimension = len(coordinates)

    except ValueError:
        raise ValueError('The coordinates must be nonempty')

    except TypeError:
        raise TypeError('The coordinates must be an iterable')


def __str__(self):
    return 'Vector: {}'.format(self.coordinates)


def __eq__(self, v):
    return self.coordinates == v.coordinates
numersoz
  • 77
  • 1
  • 1
  • 8
  • Also http://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-classes-in-python – user2357112 May 02 '17 at 23:54
  • Okay so I asked a question that was already out there. We use this to inherit object class when creating new objects. – numersoz May 03 '17 at 00:06

0 Answers0