史前第一篇,关于 类 的初次学习

 1 # -*- coding:utf-8 -*-
 2 class China(object):
 3     """
 4     Define a base class
 5     """
 6     # def __init__(self):
 7     #     print 'Our country is China'
 8 
 9     def add(self,a,b):
10         print 'The base sum is:',a+b
11 
12 class fuzhou(China):
13     """
14     Define  a child class
15     """
16     def jianfa(self,c,d):
17         print "result is:",c-d
18     def add(self,e,f):
19         print "the child SUM is:",e+f
20 
21 a1 = China()  #实例1
22 a2 = fuzhou() #实例2
23 a1.add(1,4)
24 a2.jianfa(6,3)
25 a2.add(6,7)
26 a1.add(1,1)
27 
28 
29 输出如下:
30 C:\Python27\python.exe "E:/Project/A3A XL 3G/Python_debug.py"
31 The base sum is: 5
32 result is: 3
33 the child SUM is: 13
34 The base sum is: 2
35 
36 Process finished with exit code 0

 

posted @ 2018-06-29 09:30  iSZ  阅读(233)  评论(0编辑  收藏  举报