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)