開発環境
- macOS Mojave - Apple
- Emacs (Text Editor)
- Python 3.7 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の6章(オブジェクトとクラス)、6.15(復習問題)6-9.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
print('9.')
class Bear:
def eats(self):
return 'berries'
class Rabbit:
def eats(self):
return 'clover'
class Octothorpe:
def eats(self):
return 'compers'
bear = Bear()
rabbit = Rabbit()
octothorpe = Octothorpe()
for o in [bear, rabbit, octothorpe]:
print(o.__class__, o.eats())
入出力結果(Terminal, Jupyter(IPython))
$ ./sample3.py 9. <class '__main__.Bear'> berries <class '__main__.Rabbit'> clover <class '__main__.Octothorpe'> compers $
0 コメント:
コメントを投稿