Python类学习

#!/usr/bin/env python

class Test:
	def __init__(self,msg="hello"):
		self.wel=msg
		print "init"
	def go(self,name,do):
		print self.wel+"go! "+name+" "+do
d=Test("hi,")
d.go("naughty","fight")


上面的代码演示了:

1、构造函数以及带参数(参数有默认值)构造函数

2、构造类实例

3、使用类实例调用类方法

你可能感兴趣的:(Python类学习)