開発環境
- OS X Yosemite - Apple (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Introducing Python: Modern Computing in Simple Packages(Bill Lubanovic (著)、 O'Reilly Media)のChapter 6(Oh Oh: Objects and Classes)、Things to Do 6.10.を解いてみる。
Things to Do 6.10.
コード(BBEdit)
sample10.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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):
print('Laser: {0}\nClaw: {1}\nSmart Phone: {2}'.format(
self.laser.does(), self.claw.does(), self.smart_phone.does()))
robot = Robot()
robot.does()
入出力結果(Terminal, IPython)
$ ./sample10.py Laser: disintegrate Claw: crush Smart Phone: ring $
0 コメント:
コメントを投稿