-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLearnClassPython.py
More file actions
58 lines (44 loc) · 1.17 KB
/
LearnClassPython.py
File metadata and controls
58 lines (44 loc) · 1.17 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class myClass:
"""Just one demo for me to learn class
concept in python
"""
name = ''
age = 0
__weight = 0
def f(self):
return 'hello world'
def __init__(self, n, a, w):
self.name = n
self.age = a
self.__weight = w
def speak(self):
print('I can speak')
print('%s say: I am %d years old'%(self.name, self.age))
# def __init__(self, realPart, imagePart):
# self.r = realPart
# self.i = imagePart
class people:
name = ''
age = 0
__weight = 0
def __init__(self, n, a, w):
self.name = n
self.age = a
self.__weight = w
def speak(self):
print('%s say: I am %d years old'%(self.name, self.age))
class student(people):
grad = ''
def __init__(self, n, a, w, g):
people.__init__(self,n, a, w)
self.grad = g
def speak(self):
print("%s say: I am %d years old and my grade is %d"%(
self.name, self.age, self.grad))
if __name__ == '__main__':
print('hello')
aa = myClass('tony', 10, 11)
one = people('sansa',22, 50)
one.speak()
s = student('Fzh', 24, 60, 100)
s.speak()