�N���X

�N���X���g�����R

�N���X���g������

FirstClass �̒�`
>>> class FirstClass:
	def setdata(self, value):
		self.data = value
	def display(self):
		print self.data

�C���X�^���X�I�u�W�F�N�g�̍쐬
>>> x = FirstClass()
>>> y = FirstClass()
���\�b�h�Ăяo���ɂ��f�[�^�̃Z�b�g
>>> x.setdata('King Arthur')
>>> y.setdata(3.14159)
�ʂ̃��\�b�h�Ăяo���Ńf�[�^��\��
>>> x.display()
King Arthur
>>> y.display()
3.14159

�N���X�̌p��

>>> class SecondClass(FirstClass):
	def display(self):
		print 'Current value = "%s"' % self.data

>>> z = SecondClass()
>>> z.setdata(42)
>>> z.display()
Current value = "42"

���Z�q�I�[�o�[���[�h

>>> class ThirdClass(SecondClass):
        def __init__(self, value):
            self.data = value
        def __add__(self, other):
            return ThirdClass(self.data + other)
        def __mul__(self, other):
            self.data = self.data * other

>>> a = ThirdClass("abc")
>>> a.display()
Current value = "abc"
>>> b = a + 'xyz'
>>> b.display()
Current value = "abcxyz"
>>> a * 3
>>> a.display()
Current value = "abcabcabc"

�N���X��p�����݌v

Python �� OOP

OOP�ƌp��(is-a)

employees.py �ŁAChef �� Employee �̈�� (a Chef is an Employee)

OOP�ƍ���(has-a)

pizzashop.py �ŁAPizzaShop �� Server �ƁA PizzaRobot, Oven �������Ă���B (Container object has a part object.)

OOP�Ƒ�s

(�ȗ�)

�g�ݍ��݃I�u�W�F�N�g�^�̊g��

�W���I�u�W�F�N�g�^�̎��� set.py
���p��
>>> from set import Set
>>> a = Set([1,2,3])
>>> b = Set([2,3,4])
>>> a | b
Set:[1, 2, 3, 4]
>>> x = Set('hello')
>>> x
Set:['h', 'e', 'l', 'o']

���K���

  1. Adder �Ƃ������̃N���X���쐬����B���̃N���X�� add(self, x, y) �Ƃ������\�b�h�����J���A����́A"Not Implemented"(��������Ă��Ȃ�) �Ƃ������b�Z�[�W��\��������̂Ƃ���B����Adder�̃T�u�N���X���Q�� ��`����B�����͎��̂悤��add���\�b�h������������̂Ƃ���B �����3�‚̃N���X�� adderclass.py �Ƃ������O�̃��W���[���ɍ쐬���A from adderclass import * ������A�Θb�I�ɂ����̃N���X�� �C���X�^���X���쐬����B�܂��A���ꂼ��� add���\�b�h�� �Ăяo���Ď�������B
  2. 1.�̃��W���[���t�@�C�������������āA�I�u�W�F�N�g(���X�g�܂��̓f�B�N�V���i��) ���R���X�g���N�^�̒��Ɋi�[����悤�ɂ��A�u�{�v���Z�q���I�[�o�[���[�h���� add ���\�b�h��u��������B�����̃R���X�g���N�^�Ɖ��Z�I�[�o�[���[�h �͂ǂ̃N���X�ɒu���̂��œK���낤���B