Skip to content

Instantly share code, notes, and snippets.

@kcha4github
Created June 25, 2018 16:30
Show Gist options
  • Save kcha4github/448a29009084da2ad14cee88907715c2 to your computer and use it in GitHub Desktop.
Save kcha4github/448a29009084da2ad14cee88907715c2 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class OldRobot():
def __init__(self):
self.speed = 5
def walk(self):
print("old robot walking {} km/h.".format(self.speed))
class NewRobot():
def __init__(self):
self.speed = 20
def run(self):
print("new robot running {} km/h.".format(self.speed))
robots = [OldRobot(), NewRobot()]
for robot in robots:
if hasattr(robot, "walk"):
robot.walk()
if hasattr(robot, "run"):
robot.run()
# old robot walking 5 km/h.
# new robot running 20 km/h.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment