
正文
python - class内置方法 doc/module/del(析构方法)/cal 方法
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
__doc__
# __doc__
#摘要信息
#这个属性不会继承给子类
class Test():
"""这是摘要信息"""
pass
x = Test()
print(x.__doc__)
__module__
# __module__
#查看类的出处
#从当前路径下test文件中,导入Test2 类
from test import Test2
x = Test2()
#查看x.__module__参数:
print(x.__module__)
#显示test
# __class__
# 查看类的出处
print(x.__class__)
__del__析构方法
#析构方法
# __del__
#当对象在内存中被释放时,自动触发执行.
class Test():
x = "test"
def __del__(self):
print("执行__del__方法~~~~~~")
x = Test()
#程序执行完毕后
print(x.x)
#执行了__del__方法
__cal__
# __cal__
# 对象后面加括号,触发执行
class Test():
def __call__(self, *args, **kwargs):
print("__call__方法执行..")
#没有触发类执行__call__ 方法
print(Test())
#触发__call__方法
x = Test()
x()
# __doc__
#摘要信息
#这个属性不会继承给子类 class Test():
"""这是摘要信息"""
pass x = Test()
print(x.__doc__)
# __module__
#查看类的出处 #从当前路径下test文件中,导入Test2 类
from test import Test2
x = Test2()
#查看x.__module__参数:
print(x.__module__)
#显示test # __class__
# 查看类的出处
print(x.__class__)
__del__析构方法
#析构方法
# __del__
#当对象在内存中被释放时,自动触发执行.
class Test():
x = "test"
def __del__(self):
print("执行__del__方法~~~~~~")
x = Test()
#程序执行完毕后
print(x.x)
#执行了__del__方法
__cal__
# __cal__
# 对象后面加括号,触发执行
class Test():
def __call__(self, *args, **kwargs):
print("__call__方法执行..")
#没有触发类执行__call__ 方法
print(Test())
#触发__call__方法
x = Test()
x()
#析构方法
# __del__
#当对象在内存中被释放时,自动触发执行. class Test():
x = "test" def __del__(self):
print("执行__del__方法~~~~~~") x = Test()
#程序执行完毕后
print(x.x)
#执行了__del__方法
# __cal__
# 对象后面加括号,触发执行 class Test():
def __call__(self, *args, **kwargs):
print("__call__方法执行..") #没有触发类执行__call__ 方法
print(Test()) #触发__call__方法
x = Test()
x()





