python3精要(24)-函数内省、函数注释、函数属性
生活随笔
收集整理的這篇文章主要介紹了
python3精要(24)-函数内省、函数注释、函数属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、首先,函數是對象
2、
自定義函數屬性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)-函数内省、函数注释、函数属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习Spring Boot:(二十二)使
- 下一篇: python源码精要(5)-C代码规范