发布时间:2019-09-08 09:17:20编辑:auto阅读(2900)
在C++里,函数名代表函数指针……
Python里也有类似的吧……
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 31 09:22:03 2017
@author: qcy
"""
def f1(x):
print('f1:'+x)
def f2(x):
print('f2:'+x)
def f3():
print('f3')
def f4():
print('f4')
d = {}
d[1] = f1
d[2] = f2
d[3] = f3
d[4] = f4() # 这样写, 相当于是f4()的返回值
d[1]('hello')
d[2]('world')
d[3]()
结果会这样输出。
f4 # f4是先调用的,并不是存的f4的地址……
f1:hello
f2:world
f3
上一篇: python应用系列教程——python
下一篇: MSYS添加Python
51958
51751
42048
38889
33382
30344
28988
24006
23919
22278
463°
2637°
3335°
2760°
2744°
3518°
2710°
3537°
5836°
5619°