開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の6章(オブジェクトとクラス)、6.15(復習問題)1、2、3.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3 print('6-1') class Thing: pass print(Thing) example = Thing() print(example) print('6-2') class Thing2: letters = 'abs' print(Thing2.letters) print('6-3') class Thing3: def __init__(self): self.letters = 'xyz' # クラスからオブジェクトを作ることが必要 thing3 = Thing3() print(thing3.letters)
入出力結果(Terminal, Jupyter(IPython))
$ ./sample1.py 6-1 <class '__main__.Thing'> <__main__.Thing object at 0x1039e4ac8> 6-2 abs 6-3 xyz $
0 コメント:
コメントを投稿