发布时间:2019-09-08 09:17:20编辑:auto阅读(2679)
在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
50487
49784
40381
37405
31826
28685
27615
22401
22399
20712
468°
1087°
887°
825°
1068°
945°
1557°
2911°
2598°
1999°