python类的一些相关BIF
作者:互联网
issubclass、isinstance方法
>>> class A:
pass
>>> class B(A):
pass
>>> issubclass(B,A)
True
>>> b1 = B()
>>> isinstance(b1,B)
True
hasattr、getattr、setattr方法
>>> class C:
def __init__(self,x = 0):
self.x = x
>>> c1= C()
>>> hasattr(c1,'x')
True
>>> getattr(c1,'x')
0
>>> setattr(c1,'y','FishC')
>>> getattr(c1,'y','bucunzai')
'FishC'
property方法
>>> class C:
def __init__(self,size = 10):
self.size = size
def getSize(self):
return self.size
def setSize(self,value):
self.size = value
def delSize(self):
del self.size
x = property(getSize,setSize,delSize)
>>> c1 = C()
>>> c1.getSize()
10
>>> c1.x
10
>>> c1.x = 18
>>> c1.size
18
>>> del c1.x
标签:__,python,self,BIF,相关,c1,class,def,size 来源: https://blog.csdn.net/weixin_43394725/article/details/113794075