日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第三篇:函数之对象

發布時間:2025/4/9 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第三篇:函数之对象 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 函數是第一類對象,意味著函數可以當作數據去使用

1 def foo(): 2 print('from foo') 3 4 5 #1、可以被引用 6 # print(foo) 7 # func=foo 8 # print(func) 9 # func() 10 11 #2、可以當作參數傳給另外一個函數 12 # def bar(x): #x=foo的內存地址 13 # print(x) 14 # x() 15 # 16 # bar(foo) 17 18 #3、可以當作函數的返回值 19 # def bar(): 20 # return foo 21 # 22 # f=bar() 23 # # print(f is foo) 24 # f() 25 26 #4、可以當作容器類型的元素 27 # def f1(): 28 # print('from f1') 29 # 30 # def f2(): 31 # print('from f2') 32 # 33 # l=[f1,f2] 34 # print(l) 35 # l[1]()

?實際case

1 def pay(): 2 print('pay function') 3 4 def withdraw(): 5 print('withdraw function') 6 7 def auth(): 8 print('auth function') 9 10 def shopping(): 11 print('shopping function') 12 13 def transfer(): 14 print('transfer function') 15 16 func_dic={ 17 '1':pay, 18 '2':withdraw, 19 '3':auth, 20 '4':shopping, 21 '5':transfer 22 } 23 24 # print(func_dic) 25 # func_dic['2']() 26 27 while True: 28 print(""" 29 0 退出 30 1 支付 31 2 取款 32 3 認證 33 4 購物 34 5 轉賬 35 """) 36 choice=input('請輸入您要執行的操作:').strip() #choice='123' 37 if choice == '0':break 38 if choice not in func_dic: 39 print('輸入錯誤的指令,請重新輸入') 40 continue 41 42 func_dic[choice]() #

?

轉載于:https://www.cnblogs.com/yspass/p/9325678.html

總結

以上是生活随笔為你收集整理的第三篇:函数之对象的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。