2004年05月20日 星期四 14:07
class test:
def __init__(self):
self.a=5
self.b=6
def add(self):
print self.a+self.b
return self.a+self.b
class test1(test):
def __init__(self):
test.__init__(self)
self.c=10
def add1(self):
return test.add(self)
python里面函数不用明确声明是否有返回值,有的话在函数定义里面return就行了
----- Original Message -----
From: <info at xichen.com>
To: "python-chinese" <python-chinese at lists.python.cn>
Sent: Thursday, May 20, 2004 1:17 PM
Subject: [python-chinese] python中继承的问题
> python-chinese,您好!
> 在刘鑫的帮助下,我解决了继承的问题,但是用什么方法才能让test的add方法的值和test1的add1的运算值相加呢?谢谢大家了。
> class test:
> def __init__(self):
> self.a=5
> self.b=6
> def add(self):
> print self.a+self.b
>
>
> class test1(test):
> def __init__(self):
> test.__init__(self)
> self.c=10
> def add1(self):
> test.add(self)
>
> p=test1()
> print p.a
> print p.b
> print p.c
> int(p.add())+int(p.add1())
>
> 致
> 礼!
>
>
> info
> info at xichen.com
> 2004-05-20
>
--------------------------------------------------------------------------------
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
Zeuux © 2025
京ICP备05028076号