開発環境
- 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.7.を解いてみる。
Things to Do 6.7.
コード(BBEdit)
sample7.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class Element:
def __init__(self, name, symbol, number):
self.name = name
self.symbol = symbol
self.number = number
def dump(self):
print(self.name, self.symbol, self.number)
class Element1:
def __init__(self, name, symbol, number):
self.name = name
self.symbol = symbol
self.number = number
def __str__(self):
return '{0} {1} {2}'.format(self.name, self.symbol, self.number)
d = dict(name='Hydrogen', symbol='H', number=1)
hydrogen = Element(**d)
print(hydrogen)
hydrogen = Element1(**d)
print(hydrogen)
入出力結果(Terminal, IPython)
$ ./sample7.py <__main__.Element object at 0x108874668> Hydrogen H 1 $
0 コメント:
コメントを投稿