開発環境
- 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.9.を解いてみる。
Things to Do 6.9.
コード(BBEdit)
sample9.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class Bear:
def eats(self):
print('berries')
class Rabbit:
def eats(self):
print('clover')
class Octothorpe:
def eats(self):
print('campers')
bear = Bear()
rabbit = Rabbit()
octothorpe = Octothorpe()
for animal in [bear, rabbit, octothorpe]:
animal.eats()
入出力結果(Terminal, IPython)
$ ./sample9.py berries clover campers $
0 コメント:
コメントを投稿