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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python3精要(24)-函数内省、函数注释、函数属性

發布時間:2025/3/12 python 10 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python3精要(24)-函数内省、函数注释、函数属性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、首先,函數是對象
2、

def fun1(*n):res=mysum(n)print(res)def mysum(n:list):if not n:return 0else:return n[0]+mysum(n[1:])def mys(name:'',degree:int,inc:int)->int:print(name,":",degree,"=>",inc)fun1(12,13,14,15,16,99,88) fun2=fun1 print(fun1.__name__) print(fun2.__name__) mys("張三",12,32) print(dir(fun2)) print(mysum.__annotations__) print(mys.__annotations__) __name__ 函數名 dir(fun2) 函數屬性名列表 __annotations__ 函數注釋 257 fun1 fun1 張三 : 12 => 32 ['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] {'n': <class 'list'>} {'name': '', 'degree': <class 'int'>, 'inc': <class 'int'>, 'return': <class 'int'>}

自定義函數屬性runcount

def mys(name:'',degree:int,inc:int)->int:print(name,":",degree,"=>",inc)mys.runcount=0 mys("張三",12,32) mys.runcount+=1 print(mys.runcount) print(dir(mys)) fun2=mys fun2("張三",12,32) fun2.runcount+=1 print(dir(fun2)) print(fun2.runcount) 張三 : 12 => 32 1 ['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'runcount'] 張三 : 12 => 32 ['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'runcount'] 2

總結

以上是生活随笔為你收集整理的python3精要(24)-函数内省、函数注释、函数属性的全部內容,希望文章能夠幫你解決所遇到的問題。

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