python类的继承
例子
#!/usr/bin/env python import time CheckInList = [] student_id_list = {1:‘JC‘} class school: school_name = "Oldboy Linux training center" address = "shahe Changping Distric,Beijing China." phone = ‘010-842452435‘ teachers = [‘Alex‘,‘Oldboy‘] def registration(self,s_name): latest_id = max(student_id_list.keys()) s_id = latest_id + 1 student_id_list[s_id] = [s_name] class student(school): def __init__(self,name): self.name = name def CheckIn(self,c): if c <= 930: print ‘\033[42;1m%s\033[0m checked in...‘ % self.name time.sleep(1) return self.name else: print ‘\033[42;1m%s is late...\033[0m‘ % self.name def PayTuition(self): print ‘%s paied tuition,the student id will be created soon‘ % self.name s1 = student(‘JACK‘) s2 = student(‘TOM‘) s3 = student(‘ANN‘) c_time = 929 print "start to check in :::" for s in s1,s2,s3: checkIn = s.CheckIn(c_time) if checkIn is not None: CheckInList.append(checkIn) c_time += 1 s.registration(s.name) print s1.school_name print s1.address print s1.phone print student_id_list print "NOw it‘s 8:30..." print CheckInList
本文出自 “八英里” 博客,请务必保留此出处http://5921271.blog.51cto.com/5911271/1575674
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。