函数,类,对象。
1、定义函数 def
def example(a,b,c):
return a+b*c
>>> tuna=(5,7,3)
>>> example(*tuna)
26
>>> example(5,7,3)
26
>>> def example2(**this):
print this
2、对象class
3、//其中的self指的是对象本身,例如下面的first,相当于java中的this
class className:
def createName(self,name):
self.name=name
def displayName(self):
return self.name
def saying(self):
print "hello %s" % self.name
>>> first=className()
>>> second = className()
>>> first.createName('bucky')
>>> second.createName('tondy')
>>> first.displayName()
'bucky'
>>> first.saying()
hello bucky
4、父类,子类
class parentClass:
var1="i am var1"
var2="i am var2"
>>> class childClass(parentClass):
pass
>>> parentObject=parentClass()
>>> parentObject.var1
'i am var1'
>>> childObject=childClass()
>>> childObject.var1
'i am var1'
>>> childObject.var2
'i am var2'
5、覆写父类