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