1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/usr/bin/python
class Teacher:
'Common base class for all teacher'
teacherCount = 0
def __init__(self, name, age):
self.name = name
self.age = age
Teacher.teacherCount += 1
def displayCount(self):
print "Total Teacher %d" % Teacher.teacherCount
def displayTeacher(self):
print "Name : ", self.name, ", Age: ", self.age
"This would create first object of Teacher class"
t1 = Teacher("张明", 24)
"This would create second object of Teacher class"
t2 = Teacher("李海", 30)
t1.displayTeacher()
t2.displayTeacher()
print "Total Teacher %d" % Teacher.teacherCount
"添加一属性address"
t1.address = "北京市朝阳区"
print "%s 居住在%s" % (t1.name,t1.address)
"修改一属性address"
t1.address = "北京市海淀区"
print "%s 搬家到%s" % (t1.name,t1.address)
"删除属性address"
del t1.address
print "Teacher.__doc__",Teacher.__doc__
print "Teacher.__name__",Teacher.__name__
print "Teacher.__module__",Teacher.__module__
print "Teacher.__bases__",Teacher.__bases__
print "Teacher.__dict__",Teacher.__dict__
|