Skip to content

Instantly share code, notes, and snippets.

@msyvr
Last active September 14, 2021 23:02
Show Gist options
  • Save msyvr/7cead25abcea29ed767a455673748ac0 to your computer and use it in GitHub Desktop.
Save msyvr/7cead25abcea29ed767a455673748ac0 to your computer and use it in GitHub Desktop.
python: basic inheritance
class Point:
def __init__(self, initX, initY):
self.x = initX
self.y = initY
def distanceFromOrigin(self):
return ((self.x ** 2) + (self.y ** 2)) ** 0.5
def __str__(self):
return "x=" + str(self.x) + ", y=" + str(self.y)
p = Point(7, 6)
print(p)
#class LabeledPoint(Point):
# pass
class LabeledPoint(Point):
def __init__(self, initX, initY, label):
self.x = initX
self.y = initY
self.label = label
def __str__(self):
return "x=" + str(self.x) + ", y=" + str(self.y) + " (" + self.label + ")"
labeledPt = LabeledPoint(7,6,"Here")
print(labeledPt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment