Created
June 25, 2018 16:30
-
-
Save kcha4github/448a29009084da2ad14cee88907715c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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