python usage test

Python 3.5.6 

1, js-style callback test

 1 def b():
 2     print('123')
 3 def a(fn):
 4     if callable(fn):
 5         fn()
 6 a(b)
 7 
 8 class Sample:
 9     def q(self):
10         print('q')
11     def w(self,fn):
12         if callable(fn):
13             fn()
14     def print(self):
15         self.w(self.q)
16 Sample().print()
17 Sample().w(b)
18 a(Sample().q)

Results: in line with expectations

Guess you like

Origin www.cnblogs.com/xunhanliu/p/10990396.html
Recommended