-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_7.py
More file actions
executable file
·53 lines (45 loc) · 1.39 KB
/
Copy pathpython_7.py
File metadata and controls
executable file
·53 lines (45 loc) · 1.39 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Karl.Lv@outlook.com, KarlLv@126.com
# 18 August, 2017
class myClass(object):
age = 30
def __init__(self, name):
self.name = name
def sayhi1(self):
print("sayhi1...name: {}. age: {}".format(self.name, self.age))
@staticmethod
def sayhi2(age=10):
print("sayhi2..@staticmethod..{}, {}".format(myClass.age, age))
@classmethod
def sayhi3(self, test='invoke in Instance'):
print("sayhi3..@classmethod..age: {}, {}".format(self.age, test))
@property
def sayhi4(self, name='in Instance...'):
print("sayhi4..@property..name: {}, age: {}, {}"
.format(self.name, self.age, name))
return self.name, self.age
@property
def sayhi5(self):
print("sayhi5..@property....age: {} ".format(self.age))
return self.age
if __name__ == '__main__':
m = myClass('dodo')
m.sayhi1()
print("-----@staticmethod invoke-------")
m.sayhi2('invoke in Instance...')
m.sayhi2()
myClass.sayhi2('external invoke in Class...')
myClass.sayhi2()
print("-----@classmethod invoke--------")
m.sayhi3()
myClass.sayhi3('invoke in Class')
print("-----@property invoke-----------")
print(m.sayhi4)
print(myClass.sayhi1)
print(myClass.sayhi2)
print(myClass.sayhi3)
print(myClass.sayhi4)
print(myClass.sayhi5)
print(m.sayhi5)