Python_2_Examples_and_Notes/08_class_object.py

30 lines
529 B
Python
Raw Permalink Normal View History

2017-06-11 19:42:13 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
class Calculator:
def __init__(self, ina, inb):
self.a = ina
self.b = inb
def add(self):
return self.a + self.b
def mul(self):
return self.a*self.b
newCalculation = Calculator(22,44)
print 'a+b: %d'%newCalculation.add()
print 'a*b: %d'%newCalculation.mul()
class Scientific(Calculator) :
def power(self):
return pow(self.a, self.b)
newPower = Scientific(6,7)
print 'a+b: %d'%newPower.add()
print 'a*b: %d'%newPower.mul()