開発環境
- macOS Mojave - Apple
- Emacs (Text Editor)
- Python 3.7 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の6章(オブジェクトとクラス)、6.15(復習問題)6-10.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
print('10.')
class Laser:
def does(self):
return 'disintegrate'
class Claw:
def does(self):
return 'crush'
class SmartPhone:
def does(self):
return 'ring'
class Robot:
def __init__(self):
self.laser = Laser()
self.claw = Claw()
self.smart_phone = SmartPhone()
def does(self):
for robot in [self.laser, self.claw, self.smart_phone]:
print(robot.does())
if __name__ == '__main__':
robot = Robot()
robot.does()
入出力結果(Terminal, Jupyter(IPython))
$ ./sample4.py 10. disintegrate crush ring $
0 コメント:
コメントを投稿