x = 'hello xichen' # 變量能夠引用 y = x f = f1# 函數也能夠引用 print(f1)
def f1(): print('xichen') print(f1)# f1 指向的是一塊內存地址,函數名 f1() # xichen # <function f1 at 0x0000013991191E18> # f1是函數名,能夠當參數傳給另外一個函數 def f2(name): name() f2(f1)
def f3(name): return name res = f3(f1) res()
ls=[1,2,3,f1] ls[-1]()
def pay(): print('支付1e成功') def withdraw(): print('提現2e成功') dic = { '1': pay, '2': withdraw, } while True: msg = """ '1': 支付, '2': 提現, '3': 退出, """ print(msg) choice = input('>>: ').strip() if choice == '3': break elif choice in dic: dic[choice]()
'1': 支付,
'2': 提現,
'3': 退出,
>>:1
支付1e成功python
'1': 支付,
'2': 提現,
'3': 退出,函數
>>:2
提現2e成功
'1': 支付,
'2': 提現,
'3': 退出,code
>>:3對象