我是靠谱客的博主 帅气钢铁侠,这篇文章主要介绍python构造与析构,现在分享给大家,希望可以做个参考。

#!/usr/bin/python

class Test:
	name = ""
	## like toString in Java
	def __str__(self):
		return "class Test..."

	##constructor
 	def __init__(self,name='xxx'):
		self.name = name

	##destructor
	def __del__(self):
		del self.name
		print "destructor"
		print self.name
			
test1 = Test()
print test1.name

test2 = Test("hello")
print test2.name

最后

以上就是帅气钢铁侠最近收集整理的关于python构造与析构的全部内容,更多相关python构造与析构内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(133)

评论列表共有 0 条评论

立即
投稿
返回
顶部