Python判断函数与方法
生活随笔
收集整理的這篇文章主要介紹了
Python判断函数与方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、使用types模塊的FunctionType,MethodType判斷是函數(shù)還是方法
1 def func(): 2 pass 3 4 class Foo(object): 5 6 def func(self): 7 pass 8 9 from types import FunctionType,MethodType 10 11 obj = Foo() 12 # 是否是函數(shù):False 13 print(isinstance(obj.func,FunctionType)) 14 # 是否是方法:True 15 print(isinstance(obj.func,MethodType)) 16 17 # 是否是函數(shù):True 18 print(isinstance(Foo.func,FunctionType)) 19 # 是否是方法:False 20 print(isinstance(Foo.func,MethodType))?
轉(zhuǎn)載于:https://www.cnblogs.com/bad-robot/p/10085744.html
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!總結
以上是生活随笔為你收集整理的Python判断函数与方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hbase-写操作
- 下一篇: 自兴人工智能---认识python语言的