python析构函数
#!/user/bin/python
#-*-coding:UTF-8-*-
from __future__ import print_function # 兼容python2.x和python3.x的print语句
class Fruit(object):
def __init__(self,color):# 初始化属性__color
self.__color = color
print(self.__color)
def __del__(self):# 析构函数
self.__color = ""
print("free...")
def grow(self):
print("grow...")
if __name__=="__main__":
color = "red"
fruit = Fruit(color)
fruit.grow()
参考:https://baike.baidu.com/item/%E6%9E%90%E6%9E%84%E5%87%BD%E6%95%B0/9483718?fr=aladdin
标签:__,函数,python,self,color,析构,print,grow
来源: https://www.cnblogs.com/herd/p/13769272.html